I was looking at hook_node_presave() and I tested it out and it works as described. The thing I'm puzzled about is that it doesn't take the $node parameter by reference, nor does it return anything from the function, however when I modify $node in this hook, the changes get saved. I'm really confused. Can anyone shed some light and make sense of this? How do I implement something like this?


Objects are (mostly) passed by reference in PHP. The $node variable is a stdClass object so any changes you make will be reflected on the original object in memory.

You don't need to do anything special to implement this yourself, just accept an object as an argument to a function as usual and let PHP take care of the rest.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.