function foo($a) { $gen1 = genFoo($a); $gen1->rewind(); while ($gen1->valid()) { $val = $gen1->current(); var_dump($val); $gen1->send($a); } }
function main() { $a = 42; foreach (genFoo(1) as $x) { var_dump($x); } // If we're really stopped at the beginning of this line, then // changing $a will show in $z. $z = $a; var_dump($z); }
function foo($a) { $gen1 = genFoo($a); $gen1->rewind(); while ($gen1->valid()) { $val = $gen1->current(); var_dump($val); try { $gen1->raise(new Exception('Exception given to continuation ' . $val)); } catch (Exception $e) { printf("Caught %s in foo()\n", $e->getMessage()); } } }
function foo($a) { $c = new C1(5); $i = 0; foreach (genFoo($a) as $x) { $i++; var_dump($x); } $c = new C1(6); // Runs a destructor $d = $c; $e = new C1(7); $c = null; var_dump($d); }