xref: /PHP-7.2/tests/classes/iterators_008.phpt (revision 17ccbeec)
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() {
12    echo __METHOD__ . "($this->counter)\n";
13    return $this->counter;
14  }
15
16  public function next() {
17    $this->counter--;
18    echo __METHOD__ . "($this->counter)\n";
19  }
20
21  public function rewind() {
22    echo __METHOD__ . "($this->counter)\n";
23  }
24
25  public function current() {
26    echo __METHOD__ . "($this->counter)\n";
27  }
28
29  public function key() {
30    echo __METHOD__ . "($this->counter)\n";
31  }
32
33}
34
35foreach (new D as $x) {}
36?>
37--EXPECTF--
38D::rewind(2)
39D::valid(2)
40D::current(2)
41D::next(1)
42D::valid(1)
43D::current(1)
44D::next(0)
45D::valid(0)
46