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(); try { var_dump($x->current()); } catch (Exception $e) { echo "Caught Exception\n"; } var_dump($x->current()); echo "Unsetting \$x\n"; unset($x); echo "Finishing bar()\n"; } bar();
based on VkPBs
Output for 7.0.0 - 7.2.0
Starting bar() Constructing new FooBar Destructing FooBar Caught Exception NULL Unsetting $x Finishing bar()
Output for hhvm-3.11.1 - 3.17.3
Starting bar() Constructing new FooBar Caught Exception NULL Unsetting $x Finishing bar() Destructing FooBar
Output for hhvm-3.10.1
Fatal error: syntax error, unexpected T_VARIABLE, expecting ';' in /in/Ua6J0 on line 15
Process exited with code 255.
Output for 5.5.0 - 5.6.30
Parse error: syntax error, unexpected '$f' (T_VARIABLE) in /in/Ua6J0 on line 15
Process exited with code 255.