From:             
Operating system: 
PHP version:      5.4.0RC5
Package:          SPL related
Bug Type:         Bug
Bug description:IteratorIterator doesn't iterate over DomNodeList 

Description:
------------
When creating an IteratorIterator from a DomNodeList, it doesn't behave
correctly.  The current example behaves like the iterator-key is not reset
properly when iterating although the value returned is indeed the first
entry of the iterator.


Test script:
---------------
$XML = <<< XML
<root>
  <item>1</item>
  <item>2</item>
  <item>3</item>
</root>
XML;

$dom = new DomDocument();
$dom->loadXml($XML);
$items = $dom->getElementsByTagName('item');

foreach ($items as $k => $item) {
        print "K: ".$k."  Item: ".$item->nodeName. " Value: ".$item->nodeValue.
PHP_EOL;
}

print "----" . PHP_EOL;
$it = new IteratorIterator($items);
foreach ($it as $k => $item) {
        print "K: ".$k."  Item: ".$item->nodeName. " Value: ".$item->nodeValue.
PHP_EOL;
}

Expected result:
----------------
K: 0  Item: item Value: 1
K: 1  Item: item Value: 2
K: 2  Item: item Value: 3
----
K: 0  Item: item Value: 1
K: 1  Item: item Value: 2
K: 2  Item: item Value: 3

Actual result:
--------------
K: 0  Item: item Value: 1
K: 1  Item: item Value: 2
K: 2  Item: item Value: 3
----
K: 3  Item: item Value: 1


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

Reply via email to