xref: /PHP-8.1/tests/classes/iterators_008.phpt (revision 75a678a7)
1--TEST--
2Ensure plain userspace superclass does not override special iterator behaviour on child class.
3--FILE--
4<?php
5Class C {}
6
7class D extends C implements Iterator {
8
9  private $counter = 2;
10
11  public function valid(): bool {
12    echo __METHOD__ . "($this->counter)\n";
13    return $this->counter;
14  }
15
16  public function next(): void {
17    $this->counter--;
18    echo __METHOD__ . "($this->counter)\n";
19  }
20
21  public function rewind(): void {
22    echo __METHOD__ . "($this->counter)\n";
23  }
24
25  public function current(): mixed {
26    echo __METHOD__ . "($this->counter)\n";
27    return null;
28  }
29
30  public function key(): mixed {
31    echo __METHOD__ . "($this->counter)\n";
32    return "";
33  }
34
35}
36
37foreach (new D as $x) {}
38?>
39--EXPECT--
40D::rewind(2)
41D::valid(2)
42D::current(2)
43D::next(1)
44D::valid(1)
45D::current(1)
46D::next(0)
47D::valid(0)
48