Skip to content

Stdlib: ReflectionFunction / ReflectionFunctionAbstract — basic API parity (ext/reflection/php_reflection.c) #4467

Description

@PurHur

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions