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() { try { $f = new FooBar; yield from $f; } catch (Exception $e) { echo "[foo()] Caught Exception\n"; } } function bar() { echo "Starting bar()\n"; $x = foo(); 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 EnoIO
Output for 7.0.1 - 7.2.0
Starting bar() Constructing new FooBar [foo()] Caught Exception Destructing FooBar NULL Unsetting $x Finishing bar()
Output for 7.0.0
Starting bar() Constructing new FooBar Destructing FooBar [bar()] Caught Exception Unsetting $x Finishing bar()
Output for 5.5.0 - 5.6.28
Parse error: syntax error, unexpected '$f' (T_VARIABLE) in /in/KLdee on line 16
Process exited with code 255.
Output for 5.4.0 - 5.4.45
Parse error: syntax error, unexpected 'from' (T_STRING) in /in/KLdee on line 16
Process exited with code 255.
Output for 5.1.0 - 5.3.29
Parse error: syntax error, unexpected T_STRING in /in/KLdee on line 16
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_STRING in /in/KLdee on line 16
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting '{' in /in/KLdee on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting '{' in /in/KLdee on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'{'' in /in/KLdee on line 3
Process exited with code 255.