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
Peter, I encountered a similar problem when changing over to php5. I don't know that this was the only answer or even the best answer, but I changed that line to read: $node = node_load(array('nid' => $form_values['nid'])); And my problems of duplicated data went away. Looking into node_load I never quite understood why this fixed it (and have remained suspicious that it did not). I've seen variations that name the key 'vid' rather than 'nid', which I think handles loading up the correct revision when multiple-revisions of a node are kept (a feature I don't use). I am answering in part because I'd like to have the experts on the list tear my answer apart so that I can be more confident on whether my 'fix' was actually the right approach. Scott Peter Wolanin wrote:
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
-- *Scott McLewin* www.folkjam.org find jams. post jams. play well with others. <http://www.folkjam.org>
participants (2)
-
Peter Wolanin -
Scott McLewin