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() { yield 1; try { $f = new FooBar; yield from $f; } catch (Exception $e) { echo "[foo()] Caught Exception\n"; } } function bar() { echo "Starting bar()\n"; $x = foo(); var_dump($x->current()); $x->next(); try { var_dump($x->current()); } catch (Exception $e) { echo "[bar()] Caught Exception\n"; } echo "Unsetting \$x\n"; unset($x); echo "Finishing bar()\n"; } bar();
based on oMdRC
Output for 7.0.1 - 7.2.6
Starting bar() int(1) Constructing new FooBar [foo()] Caught Exception Destructing FooBar NULL Unsetting $x Finishing bar()
Output for 7.0.0
Starting bar() int(1) Constructing new FooBar Destructing FooBar Fatal error: Uncaught Exception in /in/YsrV3:6 Stack trace: #0 [internal function]: FooBar->current() #1 /in/YsrV3(27): Generator->next() #2 /in/YsrV3(38): bar() #3 {main} thrown in /in/YsrV3 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/YsrV3 on line 17
Process exited with code 255.
Output for 5.4.10 - 5.4.45
Parse error: syntax error, unexpected '1' (T_LNUMBER) in /in/YsrV3 on line 14
Process exited with code 255.
Output for 5.3.20 - 5.3.29
Parse error: syntax error, unexpected T_LNUMBER in /in/YsrV3 on line 14
Process exited with code 255.