If node_load is called with a null node ID, it throws errors:
* warning: Invalid argument supplied for foreach() in /usr/local/apache2/drupal-4.7.4/modules/node.module on line 359.
* warning: implode() [function.implode]: Bad arguments. in /usr/local/apache2/drupal-4.7.4/modules/node.module on line 363.
* user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 query: SELECT n.nid, n.vid, n.type, n.status, n.created, n.changed, n.comment, n.promote, n.moderate, n.sticky, r.timestamp AS revision_timestamp, r.title, r.body, r.teaser, r.log, r.format, u.uid, u.name, u.picture, u.data FROM node n INNER JOIN users u ON u.uid = n.uid INNER JOIN node_revisions r ON r.vid = n.vid WHERE in /usr/local/apache2/drupal-4.7.4/includes/database.mysql.inc on line 121.
I realize you should never call node_load without a valid ID, but just in case, should node_load be modified to check if $param is valid?
if (is_numeric($param)) {
$cachable = $revision == NULL;
if ($cachable && isset($nodes[$param])) {
return $nodes[$param];
}
$cond = 'n.nid = %d';
$arguments[] = $param;
}
else if ( is_array($param) ) { //added check whether $param is an array
// Turn the conditions into a query.
foreach ($param as $key => $value) {
$cond[] = 'n.'. db_escape_string($key) ." = '%s'";
$arguments[] = $value;
}
$cond = implode(' AND ', $cond);
}
//added check to be sure at least one condition is set
if (empty($cond)) return;
Comments
Comment #1
bpocanada commentedyes, One solution is that always use array param with nid where you need to load node.
If you will use node_load(array('nid'=>id)) then that will be resolved easily.
Comment #2
ricabrantes commentedAny news?? however 4.x is no longer supported.