xref: /PHP-7.3/ext/spl/tests/iterator_025.phpt (revision 782352c5)
1--TEST--
2SPL: RecursiveIteratorIterator and begin/endIteration()
3--FILE--
4<?php
5
6class MyRecursiveIteratorIterator extends RecursiveIteratorIterator
7{
8	function beginIteration()
9	{
10		echo __METHOD__ . "()\n";
11	}
12
13	function endIteration()
14	{
15		echo __METHOD__ . "()\n";
16	}
17}
18
19$ar = array(1, 2, array(31, 32, array(331)), 4);
20
21$it = new MyRecursiveIteratorIterator(new ArrayObject($ar, 0, "RecursiveArrayIterator"));
22
23foreach($it as $v) echo "$v\n";
24
25echo "===MORE===\n";
26
27foreach($it as $v) echo "$v\n";
28
29echo "===MORE===\n";
30
31$it->rewind();
32foreach($it as $v) echo "$v\n";
33var_dump($it->valid());
34
35echo "===MANUAL===\n";
36
37$it->rewind();
38while($it->valid())
39{
40	echo $it->current() . "\n";
41	$it->next();
42	break;
43}
44$it->rewind();
45while($it->valid())
46{
47	echo $it->current() . "\n";
48	$it->next();
49}
50
51?>
52===DONE===
53<?php exit(0); ?>
54--EXPECT--
55MyRecursiveIteratorIterator::beginIteration()
561
572
5831
5932
60331
614
62MyRecursiveIteratorIterator::endIteration()
63===MORE===
64MyRecursiveIteratorIterator::beginIteration()
651
662
6731
6832
69331
704
71MyRecursiveIteratorIterator::endIteration()
72===MORE===
73MyRecursiveIteratorIterator::beginIteration()
741
752
7631
7732
78331
794
80MyRecursiveIteratorIterator::endIteration()
81bool(false)
82===MANUAL===
83MyRecursiveIteratorIterator::beginIteration()
841
851
862
8731
8832
89331
904
91MyRecursiveIteratorIterator::endIteration()
92===DONE===
93