iterators_008.phpt 836 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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(): bool {
  9. echo __METHOD__ . "($this->counter)\n";
  10. return $this->counter;
  11. }
  12. public function next(): void {
  13. $this->counter--;
  14. echo __METHOD__ . "($this->counter)\n";
  15. }
  16. public function rewind(): void {
  17. echo __METHOD__ . "($this->counter)\n";
  18. }
  19. public function current(): mixed {
  20. echo __METHOD__ . "($this->counter)\n";
  21. return null;
  22. }
  23. public function key(): mixed {
  24. echo __METHOD__ . "($this->counter)\n";
  25. return "";
  26. }
  27. }
  28. foreach (new D as $x) {}
  29. ?>
  30. --EXPECT--
  31. D::rewind(2)
  32. D::valid(2)
  33. D::current(2)
  34. D::next(1)
  35. D::valid(1)
  36. D::current(1)
  37. D::next(0)
  38. D::valid(0)