ID: 50670 User updated by: niklas at frubar dot net Reported By: niklas at frubar dot net -Status: Feedback +Status: Open Bug Type: SimpleXML related Operating System: Linux 2.6.9 x86_64 -PHP Version: 5.*, 6 +PHP Version: 5.3.* New Comment:
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)); ?> Previous Comments: ------------------------------------------------------------------------ [2010-01-11 09:16:28] j...@php.net Thank you for this bug report. To properly diagnose the problem, we need a short but complete example script to be able to reproduce this bug ourselves. A proper reproducing script starts with <?php and ends with ?>, is max. 10-20 lines long and does not require any external resources such as databases, etc. If the script requires a database to demonstrate the issue, please make sure it creates all necessary tables, stored procedures etc. Please avoid embedding huge scripts into the report. ------------------------------------------------------------------------ [2010-01-05 20:04:17] matth at mlalonde dot net Same results in 5.2.9 as with 5.2.12. ------------------------------------------------------------------------ [2010-01-05 19:37:23] niklas at frubar dot net It works with other array values, if you replace $list[] = $node->attributes(); with $c = array(); $list[] = $c; it resets the iteration at the same node. $list[] = array(); does not reset the iteration however. $list[] = new stdClass(); does reset the iteration. Adding simple integers or strings to the array do not reset. ------------------------------------------------------------------------ [2010-01-05 18:57:45] 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 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=50670&edit=1