|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2019-11-12 11:04 UTC] 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 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 12:00:01 2025 UTC | 
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