|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-01-05 18:57 UTC] niklas at frubar dot net
Description:
------------
When iterating over a large xml object and storing attributes of all
nodes in an array, somehow the iteration gets reset (always at the same
element)
Tested with 5.3.1 and php-5.3 svn HEAD, does not occur on php-5.2.12.
Reproduce code:
---------------
<?php
function traverse($node)
{
static $list;
foreach ($node->children() as $child) traverse($child);
$list[] = $node->attributes();
echo $node['id'] . "\n";
}
traverse(new SimpleXMLElement('data.xml', null, true));
data.xml:
<?xml version="1.0"?>
<rowset>
<row id="1" />
[...]
<row id="14999" />
</rowset>
Expected result:
----------------
1
2
3
[.. continuous numbers ..]
14997
14998
14999
Actual result:
--------------
1
2
3
[.. continuous numbers ..]9994
9995
9996
2
3
4
[.. continuous numbers ..]
14997
14998
14999
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 02:00:01 2025 UTC |
Reproduce Code -------------- <?php $xml = <<<XML <?xml version="1.0"?> <rowset> XML; for($i = 1; $i < 15000; $i++) $xml .= '<row id="' . $i . '" />'; $xml .= <<<XML </rowset> XML; function traverse($node) { static $list; foreach ($node->children() as $child) traverse($child); $list[] = $node->attributes(); echo $node['id'] . "\n"; } traverse(new SimpleXMLElement($xml)); ?>