Category
stdlib · php-src-strict
Problem
ReflectionFunction / ReflectionFunctionAbstract are instantiable but non-functional on the VM: construction succeeds, yet instance methods like getName() fail with "Method call on non-object" — blocking DI containers, PHPUnit-style runners, and self-host tooling that introspects named functions (e.g. compile.php entrypoints).
Parent umbrella for reflection slices: #5141 (hasReturnType), #6597 (getReturnType / isDeprecated), #4469 (ReflectionProperty::getValue/setValue), #6678 (internal functions like strlen).
Verified 2026-06-06:
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php -r "
function f(int \$x, \$y = 3): int { return \$x + \$y; }
\$r = new ReflectionFunction(\"f\");
var_dump(\$r->getName());
"'
# Method call on non-object
| Check |
Zend PHP 8.2 |
bin/vm.php |
new ReflectionFunction('f') |
ReflectionFunction object |
object (construct OK) |
->getName() |
string(1) "f" |
Method call on non-object |
->getParameters() |
array(2) |
not reached |
new ReflectionFunction('strlen') |
object |
see #6678 (existence error) |
php-src reference
Repro (inline — add test/repro-maintainer/parity_reflection_function.php in PR)
<?php
declare(strict_types=1);
function f(int $x, $y = 3): int {
return $x + $y;
}
$r = new ReflectionFunction('f');
var_dump($r->getName());
var_dump(count($r->getParameters()));
$p0 = $r->getParameters()[0];
var_dump($p0->getName());
var_dump($p0->hasType());
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php repro.php
php bin/vm.php repro.php
'
Expected Zend output: string(1) "f", int(2), string(1) "x", bool(true).
Scope (this repo)
| Layer |
Path |
| Function registry |
lib/Compiler/FunctionCompileRegistry.php or compile-time export — map function name → params, return type, file/line |
| VM object |
ext/standard/VmReflection.php — materialize ReflectionFunction handle wrapping registry entry |
| Builtin classes |
lib/VM/BuiltinClasses.php — ReflectionFunctionAbstract base + ReflectionFunction |
| Parameters |
Reuse existing ReflectionParameter materialization |
| Methods v1 |
getName, getParameters, getFileName, getStartLine, getEndLine, isUserDefined, returnsReference |
| Methods v2 |
getReturnType() → #6597; closure objects → separate issue |
| Tests |
test/compliance/cases/stdlib/reflection_function_basic.phpt |
PHP-in-PHP: metadata from compile registry in lib/; no C reflection tables (#5301 migration).
Done when
Verification
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter reflection_function'
Related
Category
stdlib· php-src-strictProblem
ReflectionFunction/ReflectionFunctionAbstractare instantiable but non-functional on the VM: construction succeeds, yet instance methods likegetName()fail with "Method call on non-object" — blocking DI containers, PHPUnit-style runners, and self-host tooling that introspects named functions (e.g.compile.phpentrypoints).Parent umbrella for reflection slices: #5141 (
hasReturnType), #6597 (getReturnType/isDeprecated), #4469 (ReflectionProperty::getValue/setValue), #6678 (internal functions likestrlen).Verified 2026-06-06:
bin/vm.phpnew ReflectionFunction('f')ReflectionFunctionobject->getName()string(1) "f"Method call on non-object->getParameters()array(2)new ReflectionFunction('strlen')php-src reference
ext/reflection/php_reflection.c—reflection_function_object_ctor,zim_ReflectionFunction_getName,getParameters,getFileName,getStartLineext/reflection/php_reflection.stub.php—ReflectionFunctionAbstracthierarchyreflection_function_ctorrejects internals — Stdlib: ReflectionFunction on internal functions — strlen/array_map throw "does not exist" (ext/reflection/php_reflection.c) #6678Repro (inline — add
test/repro-maintainer/parity_reflection_function.phpin PR)Expected Zend output:
string(1) "f",int(2),string(1) "x",bool(true).Scope (this repo)
lib/Compiler/FunctionCompileRegistry.phpor compile-time export — map function name → params, return type, file/lineext/standard/VmReflection.php— materializeReflectionFunctionhandle wrapping registry entrylib/VM/BuiltinClasses.php—ReflectionFunctionAbstractbase +ReflectionFunctionReflectionParametermaterializationgetName,getParameters,getFileName,getStartLine,getEndLine,isUserDefined,returnsReferencegetReturnType()→ #6597; closure objects → separate issuetest/compliance/cases/stdlib/reflection_function_basic.phptPHP-in-PHP: metadata from compile registry in
lib/; no C reflection tables (#5301 migration).Done when
f,2,x,hasType() === trueon VMReflectionFunctionappears inclass_exists/ extendsReflectionFunctionAbstract./script/ci-fast.sh --filter reflection_functiongreenVerification
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter reflection_function'Related