3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class X { function __construct($gen) { $this->gen = $gen; } function __destruct() { echo "__destruct: "; var_dump($this->gen->current()); echo "=====\n"; } } function gen() { $self = yield (0); echo "After yield 0\n"; yield (new X($self)); echo "After yield X\n"; return 12; } $a = gen(); var_dump($a->current()); $a->send($a); var_dump($a->current()); $a->next(); var_dump($a->getReturn());
based on I4Ug8
Output for 7.0.1 - 7.2.0
int(0) After yield 0 object(X)#2 (1) { ["gen"]=> object(Generator)#1 (0) { } } After yield X int(12) __destruct: NULL =====
Output for 7.0.0
int(0) After yield 0 object(X)#2 (1) { ["gen"]=> object(Generator)#1 (0) { } } After yield X __destruct: object(X)#2 (1) { ["gen"]=> object(Generator)#1 (0) { } } ===== int(12)
Output for 5.5.24 - 5.6.28
Parse error: syntax error, unexpected '(' in /in/f66TN on line 9
Process exited with code 255.
Output for 5.3.19 - 5.4.45
Fatal error: Call to undefined function yield() in /in/f66TN on line 9
Process exited with code 255.