If a user (like me) were to do something not so bright, like calling nodefamily_relation_load() and passing a $node that doesn't exist, the function will see that $node is not an object and try to load the node, and then call itself again passing what it thinks is now an object. However, if the node doesn't exist in the first place, calling node_load() won't return anything, and the function goes into a recursive situation and spits out lots of error messages. Changing the function to something like what's below works, but might not be the ideal solution.

function nodefamily_relation_load(&$node, $min_status = 1) {
  
  if (!is_object($node)) {
    //$node is the nid
    $node2 = node_load($node);  
    if (!is_object($node2)) {
    	return;
    }  
    return nodefamily_relation_load($node2, $min_status);
  }

  $result = db_query(db_rewrite_sql("SELECT n.nid FROM {node} n ".
            "JOIN {nodefamily} nf ON nf.child_nid = n.nid WHERE nf.parent_nid = %d AND n.status >= %d"), $node->nid, $min_status);

  $node->children = array();
  while ($row = db_fetch_object($result)) {
    if ($child = node_load($row->nid)) {
      $node->children[$child->nid] = $child;
    }
  }
  return $node->children;
}

I'm assuming that the other relation functions that use the same structure are subject to the same errors. It shouldn't be difficult to fix, but I'm not making a patch because I'm not sure what the best way to stop this is. Maybe you want more error checking/error messaging than what I did above.

Thanks
AC

Comments

fago’s picture

Status: Active » Fixed

the problem can only occur if you call the function wrong.
as stated in the phpdoc above the functions you have to pass a node object or a node id. But anyway, if committed a similar fix which returns FALSE in this case.

Anonymous’s picture

Status: Fixed » Closed (fixed)