php-src/Zend/tests/bug79927.phpt
Nikita Popov e25aab6426 Fixed bug #79927
We need to unset the AT_FIRST_YIELD flag when yielding from an
array as well.

In the interest of being conservative, I'm applying this only to
PHP 8.
2020-08-11 15:48:40 +02:00

32 lines
549 B
PHP

--TEST--
Bug #79927: Generator doesn't throw exception after multiple yield from iterable
--FILE--
<?php
$generator = (function () {
yield from [1, 2, 3];
})();
$generator->next();
$generator->next();
try {
$generator->rewind();
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
echo $generator->current(), "\n";
$generator2 = (function () {
yield from [];
yield 4;
})();
$generator2->current();
$generator2->rewind();
echo $generator2->current(), "\n";
?>
--EXPECT--
Cannot rewind a generator that was already run
3
4