Skip to content

Stdlib: ReflectionType abstract base — ReflectionNamedType must extend ReflectionType (ext/reflection/php_reflection.c) #6594

Description

@PurHur

Category

stdlib | language

Problem

Zend exposes an abstract ReflectionType base class; ReflectionNamedType, ReflectionUnionType, and ReflectionIntersectionType extend it. This compiler registers the concrete type classes in lib/VM/BuiltinClasses.php but does not register ReflectionType itself, so:

  • class_exists('ReflectionType') is false
  • is_subclass_of('ReflectionNamedType', 'ReflectionType') is false
  • instanceof ReflectionType checks in user/framework code fail

php-src reference

Repro (failure today)

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php -r "class T{function f(): int{}} \$m=new ReflectionMethod(T::class,\"f\"); \$t=\$m->getReturnType(); echo get_class(\$t),\" parent=\",get_parent_class(\$t),\" instanceof=\",var_export(\$t instanceof ReflectionType,true);"
php -r "class T{function f(): int{}} \$m=new ReflectionMethod(T::class,\"f\"); \$t=\$m->getReturnType(); echo get_class(\$t),\" parent=\",get_parent_class(\$t),\" instanceof=\",var_export(\$t instanceof ReflectionType,true);"
'
Check Zend PHP 8.2 bin/vm.php (2026-06-06)
class_exists('ReflectionType') true false
get_parent_class($namedType) ReflectionType false
$namedType instanceof ReflectionType true false

Note: ReflectionMethod::getReturnType() is also missing here — tracked in #6597 (this issue is the type hierarchy slice). Pair with #5141 (hasReturnType) and #4650 (union/intersection getTypes()).

Scope (this repo)

Component Path
Abstract class registration lib/VM/BuiltinClasses.php, lib/VM/ReflectionTypeSupport.php
Parent links Set ReflectionNamedType / union / intersection parent to ReflectionType
Shared methods allowsNull(), __toString() already on concrete classes — hoist to abstract base metadata

Implement in lib/VM/ + reflection builtins; no new C runtime.

Done when

  • class_exists('ReflectionType') is true; concrete reflection type classes report parent ReflectionType
  • is_subclass_of('ReflectionNamedType', 'ReflectionType') and instanceof ReflectionType succeed on VM
  • Compliance: test/compliance/cases/stdlib/reflection_type_hierarchy.phpt matches Zend
  • Does not regress existing reflection PHPTs

Strictness: php-src-strict

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-2:languagePhase 2 – language featuresphase-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions