Edit report at https://bugs.php.net/bug.php?id=55098&edit=1

 ID:                 55098
 User updated by:    karl dot raab at elements dot at
 Reported by:        karl dot raab at elements dot at
 Summary:            SimpleXML iteration produces infinite loop
 Status:             Open
 Type:               Bug
 Package:            SimpleXML related
 Operating System:   Linux
 PHP Version:        5.3.6
 Block user comment: N
 Private report:     N

 New Comment:

already noticed an orphan comment in the test script. 
just ignore the line "//iteration_breaker($nodes);" 

cheers, karl


Previous Comments:
------------------------------------------------------------------------
[2011-07-01 04:23:29] karl dot raab at elements dot at

Description:
------------
see the test script. 

inside the foreach-loop the call of e.g. $nodes->asXml() will reset the 
iteration 
to the beginning and therefore the loop will forever remain on the second 
element.

this may be related to bug #50670 and #51846

greets, karl

Test script:
---------------
$xmlString = "<root><a><b>1</b><b>2</b><b>3</b></a></root>";
$xml = simplexml_load_string($xmlString);

$nodes = $xml->a->b;
foreach ($nodes as $nodeData) {
    echo "nodeData: " . $nodeData . "\n";

    //the following code will break the iteration on the second element and 
resets the pointer
    //happens by any of these methods
    $xml = $nodes->asXml();
    //$nodes->getName();
    //$nodes->attributes();
    //$nodes->children();
    //$nodes->getNamespaces();
    //iteration_breaker($nodes);
}

Expected result:
----------------
nodeData: 1
nodeData: 2
nodeData: 3


Actual result:
--------------
nodeData: 1
nodeData: 2
nodeData: 2
nodeData: 2
nodeData: 2
nodeData: 2
nodeData: 2
nodeData: 2
nodeData: 2
nodeData: 2
and so on...


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=55098&edit=1

Reply via email to