xref: /PHP-8.4/Zend/tests/bug49269.phpt (revision 75a678a7)
1--TEST--
2Bug #49269 (Ternary operator fails on Iterator object when used inside foreach declaration).
3--FILE--
4<?php
5class 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
18
19$array_object = new TestObject();
20
21foreach ((true ? $array_object : $array_object) as $item) echo "$item\n";
22?>
23--EXPECT--
240
251
262
27