xref: /PHP-8.3/ext/spl/tests/iterator_008.phpt (revision f556a30b)
1--TEST--
2SPL: InfiniteIterator
3--FILE--
4<?php
5
6class ArrayIteratorEx extends ArrayIterator
7{
8    function rewind(): void
9    {
10        echo __METHOD__ . "\n";
11        parent::rewind();
12    }
13    function valid(): bool
14    {
15        echo __METHOD__ . "\n";
16        return parent::valid();
17    }
18    function current(): mixed
19    {
20        echo __METHOD__ . "\n";
21        return parent::current();
22    }
23    function key(): string|int|null
24    {
25        echo __METHOD__ . "\n";
26        return parent::key();
27    }
28    function next(): void
29    {
30        echo __METHOD__ . "\n";
31        parent::next();
32    }
33}
34
35$it = new InfiniteIterator(new ArrayIteratorEx(range(0,2)));
36
37$pos =0;
38
39foreach ($it as $v) {
40    var_dump($v);
41    if ($pos++ > 5) {
42        break;
43    }
44}
45
46?>
47--EXPECT--
48ArrayIteratorEx::rewind
49ArrayIteratorEx::valid
50ArrayIteratorEx::current
51ArrayIteratorEx::key
52int(0)
53ArrayIteratorEx::next
54ArrayIteratorEx::valid
55ArrayIteratorEx::current
56ArrayIteratorEx::key
57int(1)
58ArrayIteratorEx::next
59ArrayIteratorEx::valid
60ArrayIteratorEx::current
61ArrayIteratorEx::key
62int(2)
63ArrayIteratorEx::next
64ArrayIteratorEx::valid
65ArrayIteratorEx::rewind
66ArrayIteratorEx::valid
67ArrayIteratorEx::current
68ArrayIteratorEx::key
69int(0)
70ArrayIteratorEx::next
71ArrayIteratorEx::valid
72ArrayIteratorEx::current
73ArrayIteratorEx::key
74int(1)
75ArrayIteratorEx::next
76ArrayIteratorEx::valid
77ArrayIteratorEx::current
78ArrayIteratorEx::key
79int(2)
80ArrayIteratorEx::next
81ArrayIteratorEx::valid
82ArrayIteratorEx::rewind
83ArrayIteratorEx::valid
84ArrayIteratorEx::current
85ArrayIteratorEx::key
86int(0)
87