Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
The current API reference for node_load says:
Return value
A fully-populated node object.
But it should really say:
Return value
A fully-populated node object representing the first matching node if one is found, or boolean true otherwise.
In case the array form for $param is used and does not uniquely specify a node, the first matching node will be returned, and can vary from one call to the next.
Why "can vary" ? Because in case of a non-unique node specification in $param
, the query used does not include any ORDER BY
clause, so there is no guarantee of reproducible results.
Comment | File | Size | Author |
---|---|---|---|
#4 | node_load_doc.patch | 2.8 KB | fgm |
#1 | comment_return_value.patch | 856 bytes | Xano |
Comments
Comment #1
XanoSince only core maintainers are allowed to edit core files I moved this issue to the Drupal project.
The attached patch will update the comments with the description mentioned above.
Comment #2
Anonymous (not verified) CreditAttribution: Anonymous commentedThe last submitted patch failed testing.
Comment #3
andrewfn CreditAttribution: andrewfn commentedI wrote some code to test this and it seems that the return value is FALSE if no node is found. Inspecting the code indicates that this would be the case.
It seems rather important that this should be documented on http://api.drupal.org/api/function/node_load
Is this the right place for an issue regarding api.drupal.org?
Comment #4
fgmThis is indeed FALSE, not TRUE. Dunno what I was thinking when I typed this.
Here is the updated patch.
Comment #5
catchThis isn't correct. $vid defaults to array() when empty, but only a an int $vid can be put there for the conditions to be valid. Maybe we should default to NULL there though to make this clearer.
Comment #6
fgm@catch: it looks like your remark relates to the implementation as pertaining to the arguments, not the result documentation, does it not ?
should likely be:
but this wouldn't relate to this patch.
Comment #7
catchSorry,forgot to paste the relevant comment:
node_load() always gives you a unique node, or node revision - since it never, ever takes an array.
Comment #8
fgmThat was true in versions until 6.x, for which I created this documentation issue, but you're right: it's no longer true in 7.x: $param doesn't even exist any longer.
Resetting to 6.x since this is where the error is. Of course, the patch is not applicable.
Comment #9
valthebaldI think current documentation describes $param correctly:
so, $param really be an array
Comment #10
Xano