Skip to content

Stdlib: ReflectionConstant missing getNamespaceName/getShortName/inNamespace/getFileName/__toString (ext/reflection/php_reflection.c) #21551

Closed

Description

@PurHur

Category

stdlib · php-src-strict

Problem

ReflectionConstant (PHP 8.4+) is partially wired: getName / getValue / getAttributes / isDeprecated work, but Reflector-family APIs that php-src exposes on the class are missing. Calling them fatals with undefined method.

Repro Zend 8.4+ VM (2026-07-20, PHP_COMPILER_PROFILE=8.4)
method_exists($r,'getName') / getValue / getAttributes / isDeprecated true true
method_exists($r,'inNamespace') true false
method_exists($r,'getNamespaceName') true false
method_exists($r,'getShortName') true false
method_exists($r,'getFileName') true false
method_exists($r,'getExtension') / getExtensionName true false
method_exists($r,'__toString') true false
$r->getNamespaceName() for Foo\BAR "Foo" Fatal: undefined method

php-src reference

PHP implementation target

  • lib/VM/Builtin/ReflectionConstant*.php — add missing handlers (mirror existing GetName / GetValue / GetDeclaringClass style)
  • lib/VM/BuiltinClasses.php — register methods on ReflectionConstant under CompilerVersion::advertisesReflectionConstantClass()
  • No new C in runtime/

Repro

./script/docker-exec.sh -- bash -lc 'PHP_COMPILER_PROFILE=8.4 php bin/vm.php -r "
namespace Foo { const BAR = 1; }
\$r = new \\ReflectionConstant(\"Foo\\\\BAR\");
foreach ([\"getName\",\"getValue\",\"getAttributes\",\"isDeprecated\",\"inNamespace\",\"getNamespaceName\",\"getShortName\",\"getFileName\",\"getExtension\",\"getExtensionName\",\"__toString\"] as \$m) {
  echo \$m, \"=\", method_exists(\$r, \$m) ? \"yes\" : \"no\", PHP_EOL;
}
echo \$r->getNamespaceName(), PHP_EOL;
"'

Done when

  • method_exists true for inNamespace, getNamespaceName, getShortName, getFileName, getExtension, getExtensionName, __toString on ReflectionConstant
  • Namespace/global cases match Zend (Foo\BAR → ns Foo, short BAR; global const → empty ns / inNamespace false)
  • __toString / file / extension probes match Zend for userland and internal constants where applicable
  • Compliance guard under test/compliance/cases/stdlib/ (or reflection/)
  • php-src-strict; no php-compiler-strict shortcut

Activity

  1. added
    bugSomething isn't working
    phase-4:stdlibPhase 4 – stdlib for web apps
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jul 20, 2026
  2. PurHur commented on Jul 20, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — continuing this run

    In-flight branch fix/21551-reflection-constant-reflector-apis already has the Reflector-family APIs commit. Rebasing onto current master, verifying VM+AOT, then shipping.

    Trust probe: link OK, helloworld OK; inventory/spine were red earlier — master just merged #21563 spine tidy coverage.

  3. PurHur commented on Jul 20, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — starting this run

    Continuing in-flight fix/21551-reflection-constant-reflector-apis (2 commits ahead of master). Verifying VM+AOT for Reflector-family APIs, finishing any gaps (inNamespace), then PR/merge.

  4. PurHur commented on Jul 20, 2026

    @PurHur
    OwnerAuthor

    handoff — overlapping agent claimed at 20:49 and is mid-AOT bisect on this branch.

    Status leaving:

    • VM PROFILE=8.4/8.5 repro + compliance expectations: green (matches Zend 8.4.23 / 8.5)
    • Inventory regen committed on branch (OK 6200/6200)
    • AOT of test/repro/reflection_constant_21551.php: segfault after c:main_before_php (helper cache hit). Parallel agent stubbing JIT Call paths for bisect — leaving that work alone.

    Not merging from this run.

  5. PurHur commented on Jul 20, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — finishing this run (VM+MCJIT green; AOT method dispatch still blocked by ReflectionConstant property-read segfault — lint OK).

  6. PurHur commented on Jul 20, 2026

    @PurHur
    OwnerAuthor

    Merged via #21568

    Verification

    • VM: PHP_COMPILER_PROFILE=8.4 php bin/vm.php test/repro/reflection_constant_21551.php → namespace/short/__toString/persistent OK; inNamespace absent (matches Zend)
    • Compliance: reflection_constant_namespace_short_tostring + reflection_constant_file_extension_85 (VM+JIT) green when run on the PR branch
    • AOT: bin/compile.php -l green; standalone AOT calls to ReflectionConstant getters still segfault (pre-existing property-read path — construct OK). Follow-up: AOT ReflectionConstant method lowering.
  7. PurHur commented on Jul 21, 2026

    @PurHur
    OwnerAuthor

    cleanup: deleting abandoned AOT-bisect experiment branch agent/stdlib-21551-reflection-constant-aot (tip ea64eb8a89b2ad7daec25e8b89993eca20fb345d).

    VM Reflector APIs landed via #21568; this parallel branch iterated AOT property-store WIP (ReflectionConstantGetNamespaceName / GetShortName / ToString JIT Call stubs) that never merged. Tip SHA kept here for archaeology if a future AOT segfault follow-up needs it. No open issue references this branch.

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 machinebugSomething isn't workingimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web appsstdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions