Bug #78805 [Csd->Nab]: SimpleXMLElement::count result different
| From: | cmb@php.net | Date: | Mon, 25 Nov 2019 15:01:17 +0000 |
| Subject: | Bug #78805 [Csd->Nab]: SimpleXMLElement::count result different | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-223887@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=78805&edit=1
ID: 78805
Updated by: cmb@php.net
Reported by: yuubiseiharukana at gmail dot com
Summary: SimpleXMLElement::count result different
-Status: Closed
+Status: Not a bug
Type: Bug
Package: SimpleXML related
Operating System: Any
PHP Version: 7.4.0RC5
Block user comment: N
Private report: N
Previous Comments:
------------------------------------------------------------------------
[2019-11-25 11:47:10] yuubiseiharukana at gmail dot com
Sorry, this ticket is my mistake.
$xmlstr = <<<EOF
<a>
<bs>
<b/><b/>
</bs>
<bs><b/></bs>
<bs></bs>
</a>
EOF;
$xml = new SimpleXMLElement($xmlstr);
echo count($xml->bs); // 3
echo count($xml->bs->b); // 2 "bs->b" equals "bs[0]->b" in here
echo count($xml->bs[0]->b); // 2
echo count($xml->bs[1]->b); // 1
foreach($xml->bs as $v){ // $v loops each "bs->b"
echo count($v); // 2, 1, 0
}
$xmlstr2 = <<<EOF
<bs>
<b></b><b></b>
</bs>
<bs></bs><bs></bs>
EOF;
$xml2 = new SimpleXMLElement($xmlstr2); // Warning: SimpleXMLElement::__construct(): Entity: line 4:
parser error
------------------------------------------------------------------------
[2019-11-12 11:04:20] yuubiseiharukana at gmail dot com
Description:
------------
Test script's $xml->bs and $xml2 looks same, but count is different.
https://3v4l.org/HdLQU
Test script:
---------------
$xmlstr =
'<a><bs><b>1</b><b>2</b></bs></a>';
$xml = new SimpleXMLElement($xmlstr);
echo count($xml->bs); // 1
echo count($xml->bs->b); // 2
$xmlstr2 = '<bs><b>1</b><b>2</b></bs>';
$xml2 = new SimpleXMLElement($xmlstr2);
echo count($xml2); // 2
echo count($xml2->b); // 2
Expected result:
----------------
1212 or 2222
Actual result:
--------------
1222
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=78805&edit=1