Edit report at https://bugs.php.net/bug.php?id=62717&edit=1
ID: 62717 Updated by: larue...@php.net Reported by: php at sebastianmendel dot de Summary: BC: in PHP 5.4 empty() reports true for simplexmlelement Status: Assigned Type: Bug Package: SimpleXML related PHP Version: 5.4.5 -Assigned To: and +Assigned To: acurioso Block user comment: N Private report: N New Comment: hey, acurioso, do you have time to look at this? I assume this is introduced in https://github.com/php/php-src/commit/1e3b32c7 thanks Previous Comments: ------------------------------------------------------------------------ [2012-12-12 11:47:07] jozef at react dot com This bug was introduced in 5.4.0, as can be seen on: http://3v4l.org/MEL9Y for the following test: $string = <<<XML <a> <b>success</b> </a> XML; $xml = new SimpleXMLElement($string); $result = $xml->xpath('/a/b'); foreach ($result as $r) { if (!empty($r)) { print_r((string)$r); } else { echo 'failure'; } } ------------------------------------------------------------------------ [2012-08-01 14:37:54] php at sebastianmendel dot de Description: ------------ When laoding XML into SimpleXMLElement and iterating with ->children() empty() reports true for SimpleXMLElement objects. In PHP 5.3.16 empty() returns false. In PHP 5.4.5 empty() returns true. Test script: --------------- $xml = <<<EOT <?xml version="1.0" ?> <Y><X>6098881</X></Y> EOT; $sxml = new SimpleXMLElement($xml); foreach ($sxml->children() as $xmlKey => $xmlNode) { var_dump( empty($xmlNode), (string) $xmlNode, $xmlNode->asxml() ); } $xmlNode = new SimpleXMLElement('<X>501936634a721</X>'); var_dump( empty($xmlNode), (string) $xmlNode, $xmlNode->asxml() ); Expected result: ---------------- bool(false) string(7) "6098881" string(14) "<X>6098881</X>" bool(false) string(13) "501936634a721" string(43) "<?xml version="1.0"?> <X>501936634a721</X> " Actual result: -------------- bool(true) string(7) "6098881" string(14) "<X>6098881</X>" bool(false) string(13) "501936634a721" string(43) "<?xml version="1.0"?>\n<X>501936634a721</X>\n" ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=62717&edit=1