[development] PHP 5 and passing node by reference

Khalid B kb at 2bits.com
Sat Sep 16 01:41:09 UTC 2006

Someone reported a problem with passing nodes by reference in PHP5.


Here is the text:

hanoii - September 15, 2006 - 17:52

I was using drupal 4.7 with PHP5 with any strange behaviour until I found one.

If there is a node that is loaded twice, for example if it's shown on
the node default homepage and on some block, the links were added
twice. Then for instance add new comment and the counter of the
statics module were shown twice in the second loaded node. If its
loaded three times, then the links are three times.

Trying to figure out what was happening I saw that the node was cached
inside a static array, but I didn't understand why the cached node
that was returned by node_load the second time was the one already
modified and after some reading and testing I got to the fact that
objects are passed by reference on PHP5. So, node_view($node) is
actually passing a reference of the cached node (not a copy as on

I am sure you must be aware of this, but I wanted to ask you if you
are taking this into consideration for further releases or just stick
to PHP4 for now? Shall I submit this as an issue too? I would thing
that there may be simillar things going on inside the code as objects
are passed everywhere within the core and modules. So my plan right
now is to go back to PHP4.

Hope this helps,
Great work!

More information about the development mailing list