Bug #50670 [Opn->Ver]: Incorrect Iteration over large (10k elements) xml file

From: Date: Mon, 17 May 2010 11:37:45 +0000
Subject: Bug #50670 [Opn->Ver]: Incorrect Iteration over large (10k elements) xml file
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-150508@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=50670&edit=1

 ID:               50670
 Updated by:       mike@php.net
 Reported by:      niklas at frubar dot net
 Summary:          Incorrect Iteration over large (10k elements) xml file
-Status:           Open
+Status:           Verified
 Type:             Bug
-Package:          SimpleXML related
+Package:          Scripting Engine problem
 Operating System: Linux 2.6.9 x86_64
 PHP Version:      5.3.*

 New Comment:

Works with zend.enable_gc=0


Previous Comments:
------------------------------------------------------------------------
[2010-01-14 15:18:18] 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-01-11 09:16:28] 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-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/bug.php?id=50670&edit=1


Thread (7 messages)

« previous php.bugs (#150508) next »