php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60762 IteratorIterator doesn't iterate over DomNodeList
Submitted: 2012-01-15 14:59 UTC Modified: 2017-10-24 07:25 UTC
From: jthijssen at noxlogic dot nl Assigned:
Status: Open Package: SPL related
PHP Version: 5.4.0RC5 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2012-01-15 14:59 UTC] jthijssen at noxlogic dot nl
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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-02-04 16:11 UTC] colder@php.net
-Assigned To: +Assigned To: colder
 [2017-10-24 07:25 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: colder +Assigned To:
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC