Skip to content

Stdlib: ReflectionClass::getTraits() missing — getTraitNames() works (ext/reflection/php_reflection.c) #22108

Closed

Description

@PurHur

Category

stdlib · php-src-strict

Problem

Zend exposes ReflectionClass::getTraits() as an associative array of trait name → ReflectionClass for each trait used by the class. This compiler implements getTraitNames() but not getTraits(), so trait-aware reflection code fails at runtime.

Repro Zend 8.2 VM (2026-07-22)
method_exists(ReflectionClass::class, 'getTraits') on class C { use T; } true false
$r->getTraits() ['T' => ReflectionClass(T)] fatal: undefined method

php-src reference

PHP implementation target

Repro

./script/docker-exec.sh -- php bin/vm.php test/repro/reflection_class_get_traits.php

Done when

  • getTraits() returns the same map as Zend for single/multi-trait classes and trait aliases
  • Compliance guard under test/compliance/cases/reflection/
  • php-src-strict; VM/JIT/AOT agree when reflection is in scope

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 22, 2026
  2. PurHur commented on Jul 22, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib Advanced — batch (issues #22127, #22108, #22145, #22064, #22144; sequential PRs)

    Queued after #22127: ReflectionClass::getTraits().

  3. PurHur commented on Jul 22, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib Advanced — starting #22108 after #22127 merged (PR #22153).

    Implementing ReflectionClass::getTraits() (php-src-strict).

  4. PurHur commented on Jul 22, 2026

    @PurHur
    OwnerAuthor

    merged: #22154

    Verification

    • Zend + VM repro: keys=["T1","T2"] / empty=[] / OK
    • phpunit --filter reflection_class_get_traits: OK (2 tests, VM+JIT)
    • inventory: OK 6363/6363

    Next in batch: #22145 ReflectionParameter::canBePassedByValue() by-ref semantics

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