xref: /PHP-8.2/ext/spl/tests/iterator_025.phpt (revision b3e08881)
1--TEST--
2SPL: RecursiveIteratorIterator and begin/endIteration()
3--FILE--
4<?php
5
6class MyRecursiveIteratorIterator extends RecursiveIteratorIterator
7{
8    function beginIteration(): void
9    {
10        echo __METHOD__ . "()\n";
11    }
12
13    function endIteration(): void
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--EXPECT--
53MyRecursiveIteratorIterator::beginIteration()
541
552
5631
5732
58331
594
60MyRecursiveIteratorIterator::endIteration()
61===MORE===
62MyRecursiveIteratorIterator::beginIteration()
631
642
6531
6632
67331
684
69MyRecursiveIteratorIterator::endIteration()
70===MORE===
71MyRecursiveIteratorIterator::beginIteration()
721
732
7431
7532
76331
774
78MyRecursiveIteratorIterator::endIteration()
79bool(false)
80===MANUAL===
81MyRecursiveIteratorIterator::beginIteration()
821
831
842
8531
8632
87331
884
89MyRecursiveIteratorIterator::endIteration()
90