php-src/Zend/tests/generators/throw_already_closed.phpt
Nikita Popov be7b0bc3ec Implement Generator::throw() method
Generator::throw($exception) throws an exception into the generator. The
exception is thrown at the current point of suspension within the generator.
It basically behaves as if the current yield statement were replaced with
a throw statement and the generator subsequently resumed.
2012-12-24 00:27:55 +01:00

24 lines
360 B
PHP

--TEST--
Generator::throw() on an already closed generator
--FILE--
<?php
function gen() {
yield;
}
$gen = gen();
$gen->next();
$gen->next();
var_dump($gen->valid());
$gen->throw(new Exception('test'));
?>
--EXPECTF--
bool(false)
Fatal error: Uncaught exception 'Exception' with message 'test' in %s:%d
Stack trace:
#0 {main}
thrown in %s on line %d