3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Because lol: https://github.com/alvaropinot/circular-iterator function circularIterator(Iterator $t) { while (true) { yield $t->current(); $t->next(); 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.21, 8.3.0 - 8.3.9
Fatal error: Uncaught TypeError: circularIterator(): Argument #1 ($t) must be of type Iterator, SplFixedArray given, called in /in/5cg8t on line 17 and defined in /in/5cg8t:5 Stack trace: #0 /in/5cg8t(17): circularIterator(Object(SplFixedArray)) #1 {main} thrown in /in/5cg8t on line 5
Process exited with code 255.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.29
Fatal error: Uncaught TypeError: circularIterator(): Argument #1 ($t) must be of type Iterator, SplFixedArray given, called in /in/5cg8t on line 18 and defined in /in/5cg8t:5 Stack trace: #0 /in/5cg8t(18): circularIterator(Object(SplFixedArray)) #1 {main} thrown in /in/5cg8t on line 5
Process exited with code 255.
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.38, 7.0.0 - 7.0.33, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
int(1) int(2) int(3) int(1)

preferences:
214.81 ms | 403 KiB | 300 Q