Bug #75168 [Opn->Fbk]: Unexpected PHP Warning Node no longer exists

From: Date: Thu, 07 Sep 2017 13:06:23 +0000
Subject: Bug #75168 [Opn->Fbk]: Unexpected PHP Warning Node no longer exists
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-210994@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75168&edit=1 ID: 75168 Updated by: requinix@php.net Reported by: goetas at gmail dot com Summary: Unexpected PHP Warning Node no longer exists -Status: Open +Status: Feedback Type: Bug Package: SimpleXML related Operating System: any PHP Version: 7.0.23 Block user comment: N Private report: N New Comment: According to this https://3v4l.org/1BHKS you can use those methods on a non-existent child without warnings, but if you try them on attributes() or children() then you will get warnings. Which makes sense to me: accessing a missing node and trying basic functions on it should be safe, but continuing on to using its attributes or children after you disregarded the opportunity to check for errors (ie, if the node is missing) should create warnings. Anyway, are you asking to add warnings to the child or to remove warnings from the atttributes/children? Previous Comments: ------------------------------------------------------------------------ [2017-09-07 12:33:49] goetas at gmail dot com Description: ------------ currently the simplexml api exposes the SimpleXMLElement class when asking elements that does not exists in the XML dom, but some operations are inconsistent. $xml // instanceof \SimpleXMLElement $node = $xml->NOT_EXISTING_NODE_NAME; // instanceof \SimpleXMLElement $a = $node->attributes() // instanceof \SimpleXMLElement $b = $node->children() // instanceof \SimpleXMLElement $a->asXML() // works $a->count() // error $a->getName() // does not work // all the other method call will trigger the error Test script: --------------- <?php $xml = simplexml_load_string('<root/>'); var_dump($xml->NOT_EXISTING_NODE_NAME instanceof \SimpleXMLElement); $attributes = $xml->NOT_EXISTING_NODE_NAME->attributes(); var_dump(count($attributes)); Expected result: ---------------- bool(true) PHP Warning: count(): Node no longer exists in /home/goetas/test.php on line 7 int(0) Actual result: -------------- bool(true) PHP Warning: count(): Node no longer exists in /home/goetas/test.php on line 7 int(0) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75168&edit=1

« previous php.bugs (#210994) next »