[development] problem with PHP 5 and node_load

Peter Wolanin pwolanin at gmail.com
Sat Sep 30 21:37:22 UTC 2006


Since my Mac laptop died last weekend, I've been using a linux machine
as my localhost for testing.  I noticed some very strange behavior
testing a new feature for my recently-created volunteer_timeslots
module:

An aspect of this module is that the node view includes two forms.  I
was appending each form to the node body in hook_view as I generated
it.  Both forms have $node->nid as a value in the form and have submit
functions like:

$node = node_load($form_values['nid']);
...change the node's volunteer data...
$node->revision = TRUE;
node_save($node);

Under PHP 4 (my Mac, or linux shared host), submitting the second form
on the page works fine.

Under PHP 5, submitting the second form on the page causes the saved
node body to have the contents of the first form appended to it!  So,
my conclusion is that the object returned from node_load is not the
same during all stages of the page view.  I'd attribute this somehow
to PHP 5's behavior where all objects are passed by reference.

I can avoid the problem by storing the two forms in a tempory variable
and then appending both to the node body at the end of hook_view,
rather than appending each form to the node body as it's generated.

Is this a bug?  Am I wrong to expect node_load($nid) to always return
the same thing?

If this is a bug, maybe node_load needs to store/return a clone of the
node object?

-Peter


More information about the development mailing list