Skip to content

Stdlib: ReflectionClass::getTraitAliases() — trait adaptation map missing (ext/reflection/php_reflection.c) #6661

Closed

Description

@PurHur

Category

stdlib | runtime

Problem

ReflectionClass::getTraitAliases() returns the trait use adaptation map (alias => original) for classes that rename trait methods. The VM ReflectionClass object does not expose this method — calls fail at method_exists / fatal on invoke.

Inheritance predicates (isSubclassOf, getTraits, …) are tracked in #6302. This issue is the trait alias introspection API only.

php-src reference

Repro

test/repro-maintainer/reflection_class_trait_aliases.php:

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro-maintainer/reflection_class_trait_aliases.php
php bin/vm.php test/repro-maintainer/reflection_class_trait_aliases.php'
Runtime method_exists(getTraitAliases) Output
Zend yes array('g' => 'T::f')
VM no —

Scope (this repo)

Area Files
Trait merge Persist alias map on class entries during use Trait { f as g; } (lib/Compiler.php, lib/VM.php trait adaptation)
Reflection ReflectionClass::getTraitAliases() VM builtin in ext/standard/VmReflection.php / lib/VM/Builtin/
Register Wire method on VM ReflectionClass object alongside existing getTraits()
Tests test/repro-maintainer/reflection_class_trait_aliases.php, test/compliance/cases/stdlib/reflection_class_trait_aliases.phpt

Store alias map in PHP class metadata; do not add C reflection tables.

Done when

  • Repro: method_exists($rc, 'getTraitAliases') true on VM.
  • Class with use T { f as g; } returns ['g' => 'T::f'] matching Zend.
  • Class without aliases returns empty array (not null).
  • JIT stub optional; VM compliance is sufficient for this ticket.

Implementation (PHP-in-PHP)

  • Store trait alias map on class entries during trait merge (lib/Compiler.php / ext/standard/VmReflection.php).
  • VM builtin: ReflectionClass::getTraitAliases() in lib/VM/Builtin/ + register in reflection dispatch.
  • Optional JIT stub only after VM green.

Verification

  • Repro green on VM
  • Add test/compliance/cases/stdlib/reflection_class_trait_aliases.phpt

Strictness

php-src-strict

Activity

  1. added
    enhancementNew feature or request
    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 Jun 6, 2026
  2. PurHur commented on Jun 11, 2026

    @PurHur
    OwnerAuthor

    claim: worker-lane-B — starting this run

  3. PurHur commented on Jun 11, 2026

    @PurHur
    OwnerAuthor

    Merged via #7954

    Verification (VM):

    ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
    php bin/vm.php test/repro-maintainer/reflection_class_trait_aliases.php
    vendor/bin/phpunit --filter reflection_class_trait_aliases test/compliance/VMTest.php
    '
    • method_exists($rc, 'getTraitAliases') → true
    • getTraitAliases() → array('g' => 'T::f') for use T { f as g; }
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