Files
php-src/ext/reflection/tests/ReflectionGenerator_isClosed_002.phpt
Arnaud Le Blanc c02c1d4474 Change YIELD/YIELD_FROM to do not increment opline (#15328)
YIELD and YIELD_FROM increment opline before returning, but in most places
we need the opline to point to the YIELD and YIELD_FROM.

Here I change YIELD / YIELD_FROM to not increment opline. This simplifies the
code and fixes GH-15275 in a better way.

Closes GH-15328
2024-08-10 16:09:47 +02:00

43 lines
687 B
PHP

--TEST--
ReflectionGenerator::isClosed: ->valid() terminates an empty generator.
--FILE--
<?php
function empty_generator() {
return;
yield;
}
$gens = [
(function() {
yield;
})(),
empty_generator(),
];
foreach ($gens as $gen) {
$ref = new ReflectionGenerator($gen);
var_dump($ref->isClosed());
var_dump($gen->valid());
var_dump($ref->isClosed());
try {
var_dump($ref->getExecutingLine());
} catch (\Exception $e) {
echo $e->getMessage(), PHP_EOL;
}
echo PHP_EOL;
}
?>
--EXPECT--
bool(false)
bool(true)
bool(false)
int(10)
bool(false)
bool(false)
bool(true)
Cannot fetch information from a closed Generator