Skip to content

Commit e988e4d

Browse files
committed
Allow creating ReflectionGenerator after termination
1 parent 9acc1ed commit e988e4d

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

ext/reflection/php_reflection.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2251,7 +2251,6 @@ ZEND_METHOD(ReflectionGenerator, __construct)
22512251
{
22522252
zval *generator, *object;
22532253
reflection_object *intern;
2254-
zend_execute_data *ex;
22552254

22562255
object = ZEND_THIS;
22572256
intern = Z_REFLECTION_P(object);
@@ -2260,12 +2259,6 @@ ZEND_METHOD(ReflectionGenerator, __construct)
22602259
RETURN_THROWS();
22612260
}
22622261

2263-
ex = ((zend_generator *) Z_OBJ_P(generator))->execute_data;
2264-
if (!ex) {
2265-
_DO_THROW("Cannot create ReflectionGenerator based on a terminated Generator");
2266-
RETURN_THROWS();
2267-
}
2268-
22692262
if (intern->ce) {
22702263
zval_ptr_dtor(&intern->obj);
22712264
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
Creating ReflectionGenerator is legal after termination.
3+
--FILE--
4+
<?php
5+
6+
function foo() {
7+
yield;
8+
}
9+
10+
$gens = [
11+
(new class() {
12+
function a() {
13+
yield from foo();
14+
}
15+
})->a(),
16+
(function() {
17+
yield;
18+
})(),
19+
foo(),
20+
];
21+
22+
foreach ($gens as $gen) {
23+
foreach ($gen as $dummy);
24+
25+
$ref = new ReflectionGenerator($gen);
26+
echo $ref->getFunction()->getName(), PHP_EOL;
27+
}
28+
29+
?>
30+
--EXPECTF--
31+
a
32+
{closure:%s:%d}
33+
foo

0 commit comments

Comments
 (0)