3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function foo() { $string = (yield); echo $string; /*for ($i = 1; $i <= 3; $i++) { yield $i; }*/ } $generator = foo(); $generator->send('Hello world!'); foreach ($generator as $value) echo "$value\n";
Output for 7.0.0 - 7.1.0
Hello world! Fatal error: Uncaught Exception: Cannot traverse an already closed generator in /in/WA3cL:11 Stack trace: #0 {main} thrown in /in/WA3cL on line 11
Process exited with code 255.
Output for hhvm-3.12.0
Hello world!
Output for hhvm-3.10.0
Fatal error: Uncaught exception 'Exception' with message 'Need to call next() first' in /in/WA3cL:10 Stack trace: #0 /in/WA3cL(10): Generator->send() #1 {main}
Process exited with code 255.
Output for 5.5.0 - 5.6.28
Hello world! Fatal error: Uncaught exception 'Exception' with message 'Cannot traverse an already closed generator' in /in/WA3cL:11 Stack trace: #0 /in/WA3cL(11): unknown() #1 {main} thrown in /in/WA3cL on line 11
Process exited with code 255.
Output for 5.0.0 - 5.4.45
Notice: Use of undefined constant yield - assumed 'yield' in /in/WA3cL on line 3 yield Fatal error: Call to a member function send() on a non-object in /in/WA3cL on line 10
Process exited with code 255.
Output for 4.3.2 - 4.4.9
Notice: Use of undefined constant yield - assumed 'yield' in /in/WA3cL on line 3 yield Fatal error: Call to a member function on a non-object in /in/WA3cL on line 10
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Notice: Use of undefined constant yield - assumed 'yield' in /in/WA3cL on line 3 yield Fatal error: Call to a member function on a non-object in /in/WA3cL on line 10