[development] Open season for references
Larry Garfield
larry at garfieldtech.com
Tue Mar 6 18:49:59 UTC 2007
On Tue, 06 Mar 2007 19:15:40 +0100 (CET), "Karoly Negyesi" <karoly at negyesi.net> wrote:
>> References have a place in programming and do help with performance when
>> dealing with large objects or arrays.
>
> Wrong on arrays.
>
> http://web.archive.org/web/20060427154547/http://www.zend.com/zend/art/ref-count.php
>
> Objects in PHP4 yes but while we want Drupal working still on PHP4, it's
> not a preference or priority any more at least for me. So if there is a
> minuscule performance penalty 'cos ancient PHP versions copy around
> objects so be it. As said, if I find the need for more advanced array
> function, I will use them and reimplement them for PHP4.
And actually PHP does copy-on-write, so if you pass a 5 MB object to a function "by value" but then do not modify it, you are only using 5 MB, not 10 MB of RAM. As soon as you modify it, PHP pauses, copies the actual data in RAM (using up 10 MB total now), then modifies the copy then. There is actually slight more internal overhead for an explicit pass by reference than for a pass by value.
Of course in PHP 5, Objects are now "super resources" rather than "super arrays", so from a data-modification perspective they become effectively by reference anyway.
There are also ways to get an object through call_user_func_array() by reference in PHP 4. They're annoying, but they work.
As killes said, right tool for the job at the time.
--Larry Garfield
More information about the development
mailing list