- var_dump: documentation ( source)
<?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;
yield 3;
}
function bar() {
echo "Starting bar()\n";
$x = foo();
try {
var_dump($x->current());
} catch (Exception $e) {
echo "Caught Exception\n";
}
var_dump($x->current());
$x->next();
var_dump($x->current());
echo "Unsetting \$x\n";
unset($x);
echo "Finishing bar()\n";
}
bar();