bug49269.phpt 541 B

1234567891011121314151617181920212223242526
  1. --TEST--
  2. Bug #49269 (Ternary operator fails on Iterator object when used inside foreach declaration).
  3. --FILE--
  4. <?php
  5. class TestObject implements Iterator
  6. {
  7. public $n = 0;
  8. function valid(): bool
  9. {
  10. return ($this->n < 3);
  11. }
  12. function current(): mixed {return $this->n;}
  13. function next(): void {$this->n++;}
  14. function key(): mixed { }
  15. function rewind(): void {$this->n = 0;}
  16. }
  17. $array_object = new TestObject();
  18. foreach ((true ? $array_object : $array_object) as $item) echo "$item\n";
  19. ?>
  20. --EXPECT--
  21. 0
  22. 1
  23. 2