Category
stdlib · php-src-strict · spec refresh 2026-06-19
Problem
Zend exposes ReflectionGenerator for introspecting live Generator objects (getFunction(), getExecutingLine(), getTrace(), getThis(), etc.). Debuggers, test harnesses, and async libraries use it alongside ReflectionFiber (#4609).
This compiler runs generators on VM (#167) but ReflectionGenerator is not registered.
Verified 2026-06-19:
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php -r "var_export(class_exists(\"ReflectionGenerator\"));"'
# bool(false)
php-src reference
Repro (failure today)
<?php
declare(strict_types=1);
function gen(): Generator {
yield 1;
yield 2;
}
$g = gen();
$g->rewind();
$ref = new ReflectionGenerator($g);
echo $ref->getFunction()->getName(), "\n";
echo $ref->getExecutingLine(), "\n";
echo $ref->getExecutingFile(), "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php repro.php
php bin/vm.php repro.php 2>&1 | head -3
'
| Check |
Zend PHP 8.x |
VM today |
class_exists('ReflectionGenerator') |
true |
false ❌ |
| Repro after rewind |
prints gen, line int, file path |
Class "ReflectionGenerator" not found ❌ |
new ReflectionGenerator(new stdClass()) |
TypeError |
N/A until class exists |
v1 method surface (must implement)
| Method |
Notes |
__construct(Generator $gen) |
Reject non-generator with TypeError |
getFunction(): ReflectionFunction |
User function name |
getExecutingLine(): int |
Line of current yield/suspend |
| `getExecutingFile(): string |
false` |
getExecutingGenerator(): Generator |
PHP 8.4+ — optional same PR if small |
Defer v2: getTrace(), getThis() — follow-up OK if large.
Scope (this repo)
| Module |
Path |
| Builtin class |
ext/standard/VmReflection.php + register in reflection spine |
| State bridge |
read GeneratorState from VM (lib/VM/GeneratorState.php) |
| Tests |
test/compliance/cases/stdlib/reflection_generator.phpt |
| JIT/AOT |
defer VM-only (same as other reflection builtins) |
PHP-in-PHP: implement in ext/standard/VmReflection.php + VM hooks; no new C in runtime/.
Done when
Related
Category
stdlib· php-src-strict · spec refresh 2026-06-19Problem
Zend exposes
ReflectionGeneratorfor introspecting liveGeneratorobjects (getFunction(),getExecutingLine(),getTrace(),getThis(), etc.). Debuggers, test harnesses, and async libraries use it alongsideReflectionFiber(#4609).This compiler runs generators on VM (#167) but
ReflectionGeneratoris not registered.Verified 2026-06-19:
php-src reference
ext/reflection/php_reflection.c—ReflectionGeneratorclass, constructor guardsZend/zend_generators.c— generator execute state, trace slotsext/reflection/tests/ReflectionGenerator_*.phptRepro (failure today)
class_exists('ReflectionGenerator')truefalse❌gen, line int, file pathClass "ReflectionGenerator" not found❌new ReflectionGenerator(new stdClass())TypeErrorv1 method surface (must implement)
__construct(Generator $gen)TypeErrorgetFunction(): ReflectionFunctiongetExecutingLine(): intgetExecutingGenerator(): GeneratorDefer v2:
getTrace(),getThis()— follow-up OK if large.Scope (this repo)
ext/standard/VmReflection.php+ register in reflection spineGeneratorStatefrom VM (lib/VM/GeneratorState.php)test/compliance/cases/stdlib/reflection_generator.phptPHP-in-PHP: implement in
ext/standard/VmReflection.php+ VM hooks; no new C inruntime/.Done when
class_exists('ReflectionGenerator')true on VMTypeErrormessage matches Zend./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter reflection_generator'greenphp script/capability-matrix.phpnotesReflectionGeneratorRelated