3v4l.org

run code in 300+ PHP versions simultaneously
<?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) { var_dump($x->key()); echo "Caught Exception\n"; } echo "Unsetting \$x\n"; unset($x); echo "Finishing bar()\n"; } bar();

preferences:
47.04 ms | 402 KiB | 5 Q