$node is passed to PHP snippet by reference, and that can cause node data being unintentionally corrupted by PHP snippet evaluation, for ex. by calling code like $term = array_shift($node->taxonomy);
There should be either an option to specify if the node should be passed by ref, or cloned; or it should be always cloned; or at least the behavior should be documented and there should be warning for not using such code like the mentioned above.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | 714450_clone_fix.diff | 1.01 KB | MGN |
Comments
Comment #1
MGN commentedGenerally, this advanced option should only be used by people who understand php. There is a warning on the form page indicating it is possible to break your site if it is used incorrectly. Still, I can work on improving the documentation in the readme file.
Comment #2
MGN commentedComment #3
marrch_caat commentedYou're right, the PHP snippets shouldn't be used by someone who doesn't know PHP. But it's not obvious that the $node is passed to the snippet ByRef - and it's not a really common way, and many similar snippets in Drupal modules receive only clone of data to prevent it's modification. The purpose of the snippet id only construction of breadcrumbs data, not some actions affecting node itself. So I suppose that if there is some need to allow the snippet modifiing $node data, it should at least be made absolutely clear that the data is passed ByRef. IMHO.
Comment #4
MGN commentedI agree, and thinking about further the $node variable shouldn't be passed by reference. Do you know of an instance in the code where this is occurring? I thought it was only be passed by value...
Comment #5
marrch_caat commentedWell, I wasn't really correct using the word "byref". But it's an object, and when it's passed by value - it just can't be destroyed or replaced with a new one, but its fields can be modified or even destroyed anyway. To prevent that, it's good practice to use clone() or Drupal wrapper drupal_clone() function, and when it's about visibility or similar PHP snippets - it's usually done so. That's what I meant...
Comment #6
MGN commentedOk, I think I see what you are getting at. I think the attached patch addresses this problem, can you test it out and see if it behaves as you would expect?
Thanks
Comment #7
marrch_caat commentedYes, the patch is working as I supposed.
Comment #8
MGN commentedThanks. Committed to 6.x-2.x-dev for further testing. http://drupal.org/node/714450