php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50670 Incorrect Iteration over large (10k elements) xml file
Submitted: 2010-01-05 18:57 UTC Modified: 2010-10-22 18:06 UTC
Votes:9
Avg. Score:4.6 ± 0.7
Reproduced:8 of 8 (100.0%)
Same Version:7 (87.5%)
Same OS:6 (75.0%)
From: niklas at frubar dot net Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5.3.* OS: Linux 2.6.9 x86_64
Private report: No CVE-ID: None
 [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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-01-05 19:37 UTC] 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 20:04 UTC] matth at mlalonde dot net
Same results in 5.2.9 as with 5.2.12.
 [2010-01-11 09:16 UTC] jani@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-14 15:18 UTC] niklas at frubar dot net
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));
?>
 [2010-05-17 13:37 UTC] mike@php.net
-Status: Open +Status: Verified -Package: SimpleXML related +Package: Scripting Engine problem
 [2010-05-17 13:37 UTC] mike@php.net
Works with zend.enable_gc=0
 [2010-10-22 18:06 UTC] niklas at frubar dot net
-Status: Verified +Status: Closed
 [2010-10-22 18:06 UTC] niklas at frubar dot net
I can't reproduce it anymore with php 5.3.3, closing bug report.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC