Hi all,
I have a very strange case in new developpement of an site web. I had made a block (with a custom module) and I make a node_load. Here all is ok, the node is load, the block is display. But if I change nid of node (by exemple set null) and do nothing else (no node_save, no function call, NOTHING with this object), I have some notice of different module (like 3 or 4 modules). I know it's just notice, but I would understand why the simply fact of change variables wich is never uses, trigger some error..... Exemple :
$tmp = node_load(arg(1));
$tmp->nid=null;
=> error (lot of "Trying to get property of non-object in..." in diffrent name function)
$tmp = node_load(arg(1));
$node=$tmp;
$node->nid=null;
=> error (lot of "Trying to get property of non-object in..." in diffrent name function)
$tmp = node_load(arg(1));
$node = new stdClass();
//Copy via une boucle sinon on a des erreurs.
foreach ($tmp as $key => $value) {
if ($key != 'nid') $node->{$key} = $value;
}
=> all is ok wtf o_O
Comments
Your code makes some
Your code makes some assumptions which can lead to PHP errors, I would write
as
No the node exist I'm sure. I
No the node exist I'm sure. I put a exemple that you can reproduce on every install :
Create a node type like 'test'.
Create an module with an extra_field for example :
then a node_view for example :
Ok here all is ok we got an extra field wich display toto. Ok now let's try some basic php, always in extra field :
=> Wtf : Fatal error!
Realy strange behaviours .... and same strange if you do (like i said at top) the same in a block with a node_load (no fatal error but lot of notice)