1--TEST--
2Explicit iterator implementation
3--FILE--
4<?php
5
6class Foo implements Iterator {
7    public string $hook {
8        get => 'this is not the correct value';
9    }
10
11    private $x = ['foo', 'BAR'];
12    private $cursor = 0;
13
14    public function current(): string { return $this->x[$this->cursor]; }
15    public function key(): int { return $this->cursor; }
16    public function next(): void { ++$this->cursor; }
17    public function rewind(): void { $this->cursor = 0; }
18    public function valid(): bool { return isset($this->x[$this->cursor]); }
19}
20
21class Bar implements IteratorAggregate {
22    public string $hook {
23        get => 'this is not the correct value';
24    }
25
26    public function getIterator(): Traversable {
27        yield 1;
28        yield 2;
29    }
30}
31
32var_dump(iterator_to_array(new Foo()));
33var_dump(iterator_to_array(new Bar()));
34
35?>
36--EXPECT--
37array(2) {
38  [0]=>
39  string(3) "foo"
40  [1]=>
41  string(3) "BAR"
42}
43array(2) {
44  [0]=>
45  int(1)
46  [1]=>
47  int(2)
48}
49