iterators_008.phpt 772 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. --TEST--
  2. Ensure plain userspace superclass does not override special iterator behaviour on child class.
  3. --FILE--
  4. <?php
  5. Class C {}
  6. class D extends C implements Iterator {
  7. private $counter = 2;
  8. public function valid() {
  9. echo __METHOD__ . "($this->counter)\n";
  10. return $this->counter;
  11. }
  12. public function next() {
  13. $this->counter--;
  14. echo __METHOD__ . "($this->counter)\n";
  15. }
  16. public function rewind() {
  17. echo __METHOD__ . "($this->counter)\n";
  18. }
  19. public function current() {
  20. echo __METHOD__ . "($this->counter)\n";
  21. }
  22. public function key() {
  23. echo __METHOD__ . "($this->counter)\n";
  24. }
  25. }
  26. foreach (new D as $x) {}
  27. ?>
  28. --EXPECT--
  29. D::rewind(2)
  30. D::valid(2)
  31. D::current(2)
  32. D::next(1)
  33. D::valid(1)
  34. D::current(1)
  35. D::next(0)
  36. D::valid(0)