Bug #60762 [Asn->Opn]: IteratorIterator doesn't iterate over DomNodeList

From: Date: Tue, 24 Oct 2017 07:25:30 +0000
Subject: Bug #60762 [Asn->Opn]: IteratorIterator doesn't iterate over DomNodeList
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-212064@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=60762&edit=1

 ID:                 60762
 Updated by:         kalle@php.net
 Reported by:        jthijssen at noxlogic dot nl
 Summary:            IteratorIterator doesn't iterate over DomNodeList
-Status:             Assigned
+Status:             Open
 Type:               Bug
 Package:            SPL related
 PHP Version:        5.4.0RC5
-Assigned To:        colder
+Assigned To:        
 Block user comment: N
 Private report:     N



Previous Comments:
------------------------------------------------------------------------
[2012-01-15 14:59:23] 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



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



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


Thread (4 messages)

« previous php.bugs (#212064) next »