php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78805 SimpleXMLElement::count result different
Submitted: 2019-11-12 11:04 UTC Modified: 2019-11-25 15:01 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: yuubiseiharukana at gmail dot com Assigned:
Status: Not a bug Package: SimpleXML related
PHP Version: 7.4.0RC5 OS: Any
Private report: No CVE-ID: None
 [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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-11-25 11:47 UTC] yuubiseiharukana at gmail dot com
-Status: Open +Status: Closed
 [2019-11-25 11:47 UTC] 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-25 15:01 UTC] cmb@php.net
-Status: Closed +Status: Not a bug
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Oct 15 10:01:27 2024 UTC