xref: /PHP-8.0/ext/dom/tests/bug79852.phpt (revision 5ecc078a)
1--TEST--
2Bug #79852: count(DOMNodeList) doesn't match count(IteratorIterator(DOMNodeList))
3--SKIPIF--
4<?php require_once('skipif.inc'); ?>
5--FILE--
6<?php
7
8$XML = <<< XML
9<root>
10  <item>1</item>
11  <item>2</item>
12  <item>3</item>
13</root>
14XML;
15
16$dom = new DomDocument();
17$dom->loadXml($XML);
18$items = $dom->getElementsByTagName('item');
19
20echo "Count: ".count($items)."\n";
21echo "Count: ".iterator_count($items->getIterator())."\n";
22$it = new IteratorIterator($items);
23echo "Count: ".iterator_count($it)."\n";
24echo "Count: ".iterator_count($it)."\n";
25
26?>
27--EXPECTF--
28Count: 3
29Count: 3
30Count: 3
31
32Fatal error: Uncaught Error: Iterator does not support rewinding in %s:%d
33Stack trace:
34#0 [internal function]: InternalIterator->rewind()
35#1 [internal function]: IteratorIterator->rewind()
36#2 %s(%d): iterator_count(Object(IteratorIterator))
37#3 {main}
38  thrown in %s on line %d
39