3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Because lol: https://github.com/alvaropinot/circular-iterator function circularIterator(Iterator $t) { foreach ($t as $v) { yield $v; if (!$t->valid()) { $t->rewind(); } } } $iter = circularIterator( SplFixedArray::fromArray([1, 2, 3]) ); $iter->rewind(); var_dump($iter->current()); $iter->next(); var_dump($iter->current()); $iter->next(); var_dump($iter->current()); $iter->next(); var_dump($iter->current()); $iter->next();
Output for 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught TypeError: circularIterator(): Argument #1 ($t) must be of type Iterator, SplFixedArray given, called in /in/2arts on line 15 and defined in /in/2arts:5 Stack trace: #0 /in/2arts(15): circularIterator(Object(SplFixedArray)) #1 {main} thrown in /in/2arts on line 5
Process exited with code 255.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28
Fatal error: Uncaught TypeError: circularIterator(): Argument #1 ($t) must be of type Iterator, SplFixedArray given, called in /in/2arts on line 16 and defined in /in/2arts:5 Stack trace: #0 /in/2arts(16): circularIterator(Object(SplFixedArray)) #1 {main} thrown in /in/2arts on line 5
Process exited with code 255.
Output for 5.5.0 - 5.5.35, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33
int(1) int(2) int(3) NULL

preferences:
169.26 ms | 403 KiB | 213 Q