3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class FooBar implements Iterator { function __construct() { echo "Constructing new FooBar\n"; } function __destruct() { echo "Destructing FooBar\n"; } function current () { throw new Exception; } function key () { return 0; } function next () {} function rewind () {} function valid () { return true; } } function foo() { $f = new FooBar; yield from $f; } function bar() { echo "Starting bar()\n"; $x = foo(); var_dump($x->current()); try { $x->next(); } catch (Exception $e) {} var_dump($x->current()); try { $x->next(); } catch (Exception $e) {} var_dump($x->current()); try { $x->next(); } catch (Exception $e) {} echo "Unsetting \$x\n"; unset($x); echo "Finishing bar()\n"; } bar();
based on WM1ok
Output for 7.0.0 - 7.2.0
Starting bar() Constructing new FooBar Destructing FooBar Fatal error: Uncaught Exception in /in/gMZC8:6 Stack trace: #0 [internal function]: FooBar->current() #1 /in/gMZC8(21): Generator->current() #2 /in/gMZC8(32): bar() #3 {main} thrown in /in/gMZC8 on line 6
Process exited with code 255.
Output for 5.5.24 - 5.6.28
Parse error: syntax error, unexpected '$f' (T_VARIABLE) in /in/gMZC8 on line 15
Process exited with code 255.
Output for 5.4.9 - 5.4.45
Parse error: syntax error, unexpected 'from' (T_STRING) in /in/gMZC8 on line 15
Process exited with code 255.
Output for 5.3.19 - 5.3.29
Parse error: syntax error, unexpected T_STRING in /in/gMZC8 on line 15
Process exited with code 255.