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
PHP Version: 5.3.26
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[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