Whilst doing some weird stuff at chx's suggestion, I stumbled across a problem in the node_invoke() function. node_invoke() first checks to see if a node module implements a given hook, then if it does it invokes it and returns the result. If it doesn't, however, then it returns nothing. Since node_invoke() is sometimes called from array_merge() or array_merge_recursive(), that causes a problem since the second parameter to array_merge() is then a NULL value rather than an array.
This patch fixes the problem by adding a default return array() to the function, so that it always returns an array as expected, even if the hook is not found.
| Comment | File | Size | Author |
|---|---|---|---|
| node_invoke.patch.txt | 459 bytes | Crell |
Comments
Comment #1
steph commentedThe code seems good (you just return an empty array), but can you provide a testcase to reproduce this bug?
Comment #2
Crell commentedWell I ended up not doing that method anyway, so I don't have the trouble code handy at the moment. IIRC, I was trying to use nodeapi to modify my own node rather than use using the standard node hooks, and then since the standard node routines then couldn't find the node hooks it was choking. (Yes that's silly and Ber suggested a far better way to do what I was trying to do, which I am now doing. There may be other cases where it would come up.)
It's not an issue that should come up often, I suspect, but it's still bad form to have an indeterminant return from a function.
Comment #3
killes@www.drop.org commentedmoving to cvs
Comment #4
killes@www.drop.org commentedNot all of the functions called by node_invoke return arrays, according to chx.
Comment #5
chx commentedhook_form and hook_node_info return arrays, hook_access returns a boolean, hook_load returns an object and anyone is free to define an arbitrary hook with whatever return. If that's a string, then you are in deep trouble -- NULL converts to '' but array() converts to Array.