3v4l.org

run code in 300+ PHP versions simultaneously
<?php $foo = function () { var_dump('foo'); yield 1; yield 2; yield 3; }; $iterator = new CachingIterator($foo()); foreach ($iterator as $value) { var_dump($value); } foreach ($iterator as $value) { var_dump($value); }
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
string(3) "foo" int(1) int(2) int(3) Fatal error: Uncaught Exception: Cannot rewind a generator that was already run in /in/dgAFs:16 Stack trace: #0 /in/dgAFs(16): CachingIterator->rewind() #1 {main} thrown in /in/dgAFs on line 16
Process exited with code 255.

preferences:
157.16 ms | 404 KiB | 190 Q