3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function gen() { for($i = 1; $i <=3; $i++) { $resp = (yield $i); echo '$resp: '; var_dump($i); } } $gen = gen(); foreach($gen as $out) { echo '$i: '; var_dump($i); $gen->send('Hi ' . $i); }
Output for 5.6.30, 7.0.0 - 7.2.9
$i: Notice: Undefined variable: i in /in/AK9N7 on line 17 NULL Notice: Undefined variable: i in /in/AK9N7 on line 18 $resp: int(1) $resp: int(2) $i: Notice: Undefined variable: i in /in/AK9N7 on line 17 NULL Notice: Undefined variable: i in /in/AK9N7 on line 18 $resp: int(3)
Output for hhvm-3.20.2, hhvm-3.22.0
$i: Notice: Undefined variable: i in /in/AK9N7 on line -1 NULL Notice: Undefined variable: i in /in/AK9N7 on line -1 $resp: int(1) $resp: int(2) $i: Notice: Undefined variable: i in /in/AK9N7 on line -1 NULL Notice: Undefined variable: i in /in/AK9N7 on line -1 $resp: int(3) Fatal error: Uncaught exception 'Exception' with message 'Generator is already finished' in /in/AK9N7:-1 Stack trace: #0 /in/AK9N7(-1): Generator->next() #1 {main}
Process exited with code 255.
Output for hhvm-3.15.4 - 3.19.2, hhvm-3.21.0 - 3.21.3
$i: Notice: Undefined variable: i in /in/AK9N7 on line 17 NULL Notice: Undefined variable: i in /in/AK9N7 on line 18 $resp: int(1) $resp: int(2) $i: Notice: Undefined variable: i in /in/AK9N7 on line 17 NULL Notice: Undefined variable: i in /in/AK9N7 on line 18 $resp: int(3) Fatal error: Uncaught exception 'Exception' with message 'Generator is already finished' in /in/AK9N7:19 Stack trace: #0 /in/AK9N7(19): Generator->next() #1 {main}
Process exited with code 255.