Bug #78805 [Opn->Csd]: SimpleXMLElement::count result different

From: Date: Mon, 25 Nov 2019 11:47:10 +0000
Subject: Bug #78805 [Opn->Csd]: SimpleXMLElement::count result different
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-223880@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 User updated by: yuubiseiharukana at gmail dot com Reported by: yuubiseiharukana at gmail dot com Summary: SimpleXMLElement::count result different -Status: Open +Status: Closed Type: Bug Package: SimpleXML related Operating System: Any PHP Version: 7.4.0RC5 Block user comment: N Private report: N New Comment: 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 Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#223880) next »