3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php // $gen = (function () { yield from range('a', 'z'); })(); function xrange() { foreach (range('a','z') as $l) yield $l; } $gen = xrange(); $c = 0; foreach ($gen as $k => $v) { echo $v . PHP_EOL; if ($c++ > 2) { break; } } foreach ($gen as $k => $v) { echo $v . PHP_EOL; break; }
based on u9LpT
Output for 7.0.0 - 7.3.0rc3
a b c d Fatal error: Uncaught Exception: Cannot rewind a generator that was already run in /in/Zs7Hi:17 Stack trace: #0 {main} thrown in /in/Zs7Hi on line 17
Process exited with code 255.
Output for hhvm-3.15.4
a b c d d
Output for 5.6.0 - 5.6.30
a b c d Fatal error: Uncaught exception 'Exception' with message 'Cannot rewind a generator that was already run' in /in/Zs7Hi:17 Stack trace: #0 /in/Zs7Hi(17): unknown() #1 {main} thrown in /in/Zs7Hi on line 17
Process exited with code 255.