Edit report at https://bugs.php.net/bug.php?id=65172&edit=1
ID: 65172 User updated by: scruoge at gmail dot com Reported by: scruoge at gmail dot com Summary: SimpleXMLElement::children() incorrect behavior Status: Open Type: Bug Package: SimpleXML related Operating System: Windows & Linux PHP Version: 5.3.26 Block user comment: N Private report: N New Comment: Yes, I agree. As I suspected it's a documentation problem. Previous Comments: ------------------------------------------------------------------------ [2013-07-19 19:07:15] mail+php at requinix dot net ...Attributes can't have children. If you mean the difference between returning an empty SimpleXMLElement object versus returning null, I can see that as a doc bug: Return Values for children() should say "Returns NULL if called on a SimpleXMLElement object that represents an attribute and not a tag." as it does for attributes(). ------------------------------------------------------------------------ [2013-07-01 09:27:51] scruoge at gmail dot com The bug is also reproducible in Linux environment. ------------------------------------------------------------------------ [2013-07-01 07:58:40] scruoge at gmail dot com There's extra string in the code that should be removed: (line 6) $xres = array_shift($xml->xpath('childNode/@attr')); It does not affect test script result, though it generates E_STRICT notice. ------------------------------------------------------------------------ [2013-07-01 07:54:26] scruoge at gmail dot com Description: ------------ XPath, selecting attribute returns SimpleXMLElement, which's children() method returns NULL. Probably it's a documentation issue. It says "Returns a SimpleXMLElement element, whether the node has children or not." Test script: --------------- <?php $s = '<rootNode><childNode attr="attrval" attr2="attr2val">nodeContents</childNode></rootNode>'; $xml = new SimpleXMLElement($s); $xpathres = $xml->xpath('childNode/@attr'); $xres = array_shift($xpathres); $xres = array_shift($xml->xpath('childNode/@attr')); echo '$xres->children() result: '; var_dump($xres->children()); echo 'typecast result: '; var_dump((string) $xres); Expected result: ---------------- $xres->children() result: object(SimpleXMLElement)#2 (0) { } typecast result: string(7) "attrval" Actual result: -------------- $xres->children() result: NULL typecast result: string(7) "attrval" ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=65172&edit=1