xref: /PHP-8.3/ext/spl/tests/array_020.phpt (revision f556a30b)
1--TEST--
2SPL: ArrayIterator overloading
3--FILE--
4<?php
5
6class ArrayIteratorEx extends ArrayIterator
7{
8    function rewind(): void
9    {
10        echo __METHOD__ . "\n";
11        ArrayIterator::rewind();
12    }
13
14    function valid(): bool
15    {
16        echo __METHOD__ . "\n";
17        return ArrayIterator::valid();
18    }
19
20    function key(): string|int|null
21    {
22        echo __METHOD__ . "\n";
23        return ArrayIterator::key();
24    }
25
26    function current(): mixed
27    {
28        echo __METHOD__ . "\n";
29        return ArrayIterator::current();
30    }
31
32    function next(): void
33    {
34        echo __METHOD__ . "\n";
35        ArrayIterator::next();
36    }
37}
38
39$ar = new ArrayIteratorEx(array(1,2));
40foreach($ar as $k => $v)
41{
42    var_dump($k);
43    var_dump($v);
44}
45
46?>
47--EXPECT--
48ArrayIteratorEx::rewind
49ArrayIteratorEx::valid
50ArrayIteratorEx::current
51ArrayIteratorEx::key
52int(0)
53int(1)
54ArrayIteratorEx::next
55ArrayIteratorEx::valid
56ArrayIteratorEx::current
57ArrayIteratorEx::key
58int(1)
59int(2)
60ArrayIteratorEx::next
61ArrayIteratorEx::valid
62