Closed (won't fix)
Project:
Drupal core
Version:
6.x-dev
Component:
node system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Anonymous (not verified)
Created:
15 Jan 2007 at 18:21 UTC
Updated:
21 Aug 2018 at 03:30 UTC
Jump to comment: Most recent
Comments
Comment #1
Jaza commentedSeems like a good idea, that would make things cleaner and more consistent. However, I doubt that this would have much performance improvement (if any), since many PHP experts have consistently stated that passing by ref is not faster than passing by value (in fact, it can often be slower), due to optimisation processes in the PHP interpreter.
Comment #2
chx commentedWith objects on PHP4, I am unsure. Please run this on PHP4
On PHP5 this prints 152 bytes so in PHP5 there is certainly no point in this patch.
Comment #3
Anonymous (not verified) commentedBoth Jaza and Chx, the savings isn't from the entry point of the function. The savings is at the exit point of the function. Currently the $node variable is returned and that value is needed to be stored again.
The pass by ref patch saves the need to return the object and store it again in the calling object.
Comment #4
AjK commentedOn PHP4 assignment by function call will copy the object (as opposed to bump it's ref count). So, in PHP4 there's a fractional improvement in speed. The speed improvement is, however, hardly worth mentioning.
The benefit this brings is weighted in terms of a greater loss in maintainerbility. Directly equating the return value is far more readable than abstractly passing a reference.
As chx points out, in PHP5 this patch makes no difference, by methods bump the zval refcount by 1 so no gain, just a loss of maintainerbility.
So, purely on the maintainerbility it's a "won't fix".
Comment #5
Anonymous (not verified) commentedSo you say
is no different than
Comment #6
Anonymous (not verified) commentedLet me restate
So you say
is no different than
Comment #7
chx commentedhttp://php.net/manual/en/language.oop5.basic.php says that
.
So, again, as AJK said, while the patch has some merits on PHP4, there is none on PHP5. If these would be in a loop, called several hundreds time on one page, then not doing the in-memory copying for PHP4 could have some impact.
Comment #8
Anonymous (not verified) commentedObjects and arrays are the same I suppose. The fix does save a few bytes and possibly a microsecond or two of time for every node on every server displayed on every page and every module that uses the functions. How many times do these functions get called? I remember some comment that Dries wanted to tweek the resource use bit by bit and I commited this patch in cooperation with that and another patch that was committed to 5 that changed a function to accept the node array with call by ref. This patch was a complement to the patch that was committed.
Comment #9
Crell commentedWell, no. In PHP 4 they behaved the same way. An object is basically an array with methods attached to it. In PHP 5, that's no longer the case. They're more *resources* with methods attached to them. That's how they effectively are "passed by reference" by default. (More specifically, they are passed by value but the value is no longer the object but a pointer to it, just like in Java.)
In either case, though, you should only pass by reference if you want reference-esque functionality. PHP does the performance saving for you if it can. It's nice like that.