3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function gen_one_to_three() { for ($i = 1; $i <= 3; $i++) { $a = yield; echo $a; } } $generator = gen_one_to_three(); foreach ($generator as $value) { $generator->send('cheese'); var_dump($value); }
Output for 5.5.0 - 5.6.28, 7.0.0 - 7.1.0
cheeseNULL cheeseNULL
Output for hhvm-3.10.0 - 3.12.0
cheeseNULL cheeseNULL Fatal error: Uncaught exception 'Exception' with message 'Generator is already finished' in /in/RRut3:15 Stack trace: #0 /in/RRut3(15): Generator->next() #1 {main}
Process exited with code 255.
Output for 5.2.3 - 5.4.45
yieldyieldyield Warning: Invalid argument supplied for foreach() in /in/RRut3 on line 12
Output for 4.3.0 - 4.3.10, 4.4.0 - 5.2.2
yieldyieldyield<br /> <b>Warning</b>: Invalid argument supplied for foreach() in <b>/in/RRut3</b> on line <b>12</b><br />
Output for 4.3.11
yieldyieldyield