#27139 [Bgs]: can't iterate thru simplexml_element objects in normal ways
| From: | helly@php.net | Date: | Wed, 04 Feb 2004 19:56:23 +0000 |
| Subject: | #27139 [Bgs]: can't iterate thru simplexml_element objects in normal ways | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-54406@lists.php.net to get a copy of this message | ||
ID: 27139
Updated by: helly@php.net
Reported By: kennyt@php.net
Status: Bogus
Bug Type: *XML functions
PHP Version: 5CVS-2004-02-03 (dev)
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2004-02-04 08:11:09] kennyt@php.net
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 02:28:35] helly@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
As Adam said, use foreach.
------------------------------------------------------------------------
[2004-02-03 23:55:32] adam at trachtenberg dot com
No. You need to use foreach() or the iterator magic
won't work.
------------------------------------------------------------------------
[2004-02-03 22:16:05] kennyt@php.net
Description:
------------
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(
'<a>
<b></b>
<b></b>
<b></b>
</a>');
while(list($foo, $bar) = each($xml->b)) {
echo '"' , $foo , '" - "', $bar , '"' , chr(10);
}
--OR--
for($i = 0; $i < count($xml->b); ++$i) {
echo '"' , $i , '" - "', $xml->b[$i] , '"' ,
chr(10);
}
Expected result:
----------------
[3 lines of output]
--OR--
"0" - ""
"1" - ""
"2" - ""
Actual result:
--------------
[no output]
--OR--
"0" - ""
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=27139&edit=1