From:             amfriedman at gmail dot com
Operating system: Unbuntu 11
PHP version:      5.3.25
Package:          SimpleXML related
Bug Type:         Bug
Bug description:SimpleXMLIterator unintentionally rewinds to beginning

Description:
------------
---
>From manual page: http://php.net/manual/en/class.simplexmliterator.php
---


When under a for-loop and iterating through a SimpleXMLIterator object,
merely 
reading from a variable that stores the children being iterated will cause
a 
rewind to the beginning of the object within which you are looping.

Test script:
---------------
$xml = new SimpleXMLIterator($xml_str);

$nodes = $nodes_for_lookup = $xml->children();

$n_node = -1;
                
for($nodes->rewind(); $nodes->valid(); $nodes->next()) {
  $node = $nodes->current();
  $n_node++;

  // This rewinds this loop
  $value_to_check = $nodes[$n_node+1];
  
  // This also rewinds the loop
  $value_to_check = $nodes_for_lookup[$n_node+1];

  // This does NOT rewind the loop (expected behavior)
  $nodes_now = $xml->children();
  $value_to_check = $nodes_now[$n_node+1];
}
                                                

Expected result:
----------------
The loop should NOT be rewound!  Merely reading from the object should not
affect 
the iterator's pointer whatsoever.

Actual result:
--------------
The loop is getting rewound due to reading a specific key-based item in the

iterator object/array.

-- 
Edit bug report at https://bugs.php.net/bug.php?id=64813&edit=1
-- 
Try a snapshot (PHP 5.4):   
https://bugs.php.net/fix.php?id=64813&r=trysnapshot54
Try a snapshot (PHP 5.3):   
https://bugs.php.net/fix.php?id=64813&r=trysnapshot53
Try a snapshot (trunk):     
https://bugs.php.net/fix.php?id=64813&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=64813&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=64813&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=64813&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=64813&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=64813&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=64813&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=64813&r=notwrong
Not enough info:            
https://bugs.php.net/fix.php?id=64813&r=notenoughinfo
Submitted twice:            
https://bugs.php.net/fix.php?id=64813&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=64813&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=64813&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=64813&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=64813&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=64813&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=64813&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=64813&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=64813&r=mysqlcfg

Reply via email to