Skip to content

Stdlib: ReflectionUnionType / ReflectionIntersectionType — getTypes() parity (ext/reflection/php_reflection.c) #4650

Description

@PurHur

Category

stdlib

Problem

ReflectionUnionType and ReflectionIntersectionType classes are registered in lib/VM/BuiltinClasses.php, but getTypes() is not implemented — the method table is empty ([]). Zend returns an array of ReflectionNamedType (or nested union/intersection) objects for composite parameter/return/property types.

Without this, reflection-based DI containers, static analyzers, and bootstrap inventory tools cannot introspect union/intersection type hints.

php-src reference

Repro (failure today)

Save as repro_reflection_composite_types.php:

<?php
class C {
    public function m(string|int $x, Countable&Traversable $y): void {}
}
$rm = new ReflectionMethod(C::class, 'm');
$union = $rm->getParameters()[0]->getType();
$inter = $rm->getParameters()[1]->getType();
echo get_class($union), "\n";
echo get_class($inter), "\n";
var_export(method_exists($union, 'getTypes'));
var_export(method_exists($inter, 'getTypes'));
// Zend: both true; getTypes() returns ReflectionNamedType[] / nested composites
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php repro_reflection_composite_types.php
php bin/vm.php repro_reflection_composite_types.php
'
Check Zend This compiler
get_class($union) ReflectionUnionType likely matches
method_exists($union, 'getTypes') true false (empty method table)
count($union->getTypes()) 2 fatal / undefined method

Scope (this repo)

Area Files Notes
VM reflection ext/standard/VmReflection.php, new ReflectionUnionTypeGetTypes.php, ReflectionIntersectionTypeGetTypes.php Walk stored composite type metadata from compile time
Compiler lib/Compiler.php — type hint metadata on parameters/properties Ensure union/intersection members persisted for reflection
Builtin classes lib/VM/BuiltinClasses.php Wire methods into registration
Tests test/compliance/cases/stdlib/reflection_union_intersection_types.phpt
JIT/AOT phase 2 VM-first

Done when

Links

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