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'); echo "$value\n"; }
Output for 5.5.0 - 5.6.28, 7.0.0 - 7.1.0
cheese cheese
Output for hhvm-3.10.0 - 3.12.0
cheese cheese Fatal error: Uncaught exception 'Exception' with message 'Generator is already finished' in /in/6oF4Z:15 Stack trace: #0 /in/6oF4Z(15): Generator->next() #1 {main}
Process exited with code 255.
Output for 4.3.0 - 4.3.10, 4.4.0 - 5.4.45
Notice: Use of undefined constant yield - assumed 'yield' in /in/6oF4Z on line 6 yield Notice: Use of undefined constant yield - assumed 'yield' in /in/6oF4Z on line 6 yield Notice: Use of undefined constant yield - assumed 'yield' in /in/6oF4Z on line 6 yield Warning: Invalid argument supplied for foreach() in /in/6oF4Z on line 12
Output for 4.3.11
Notice: Use of undefined constant yield - assumed 'yield' in /in/6oF4Z on line 6 yield Notice: Use of undefined constant yield - assumed 'yield' in /in/6oF4Z on line 6 yield Notice: Use of undefined constant yield - assumed 'yield' in /in/6oF4Z on line 6 yield