|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27139 can't iterate thru simplexml_element objects in normal ways
Submitted: 2004-02-03 22:16 UTC Modified: 2004-02-04 14:56 UTC
From: Assigned:
Status: Not a bug Package: *XML functions
PHP Version: 5CVS-2004-02-03 (dev) OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
New email:
PHP Version: OS:


 [2004-02-03 22:16 UTC]
We should be able to use normal array iteration 
techniques when going through such pseudoarray 
structures in simplexml elements, right?

Reproduce code:
$xml = simplexml_load_string(

while(list($foo, $bar) = each($xml->b)) {
  echo '"' , $foo , '" - "', $bar , '"' , chr(10);


for($i = 0; $i < count($xml->b); ++$i) {
  echo '"' , $i , '" - "', $xml->b[$i] , '"' , chr(10);

Expected result:
[3 lines of output]


"0" - ""
"1" - ""
"2" - ""

Actual result:
[no output]


"0" - ""


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-02-03 23:55 UTC] adam at trachtenberg dot com
No. You need to use foreach() or the iterator magic 
won't work.
 [2004-02-04 02:28 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

As Adam said, use foreach.
 [2004-02-04 08:11 UTC]
Okay, does foreach do its usual copy job on the set, or 
is it a simulated foreach? And if it's the former, does 
that really matter? (They're just pointers, right?)
 [2004-02-04 14:56 UTC]
Depends on the actual iterator being executed. For the simpeXML_Element class there will be no copy. And even in the whole ext/SPL there will be no copying.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jul 15 04:01:28 2024 UTC