Skip to content

Stdlib: ReflectionMethod::getReturnType() / isDeprecated() / hasTentativeReturnType() — typed return introspection (ext/reflection/php_reflection.c) #6597

Description

@PurHur

Category

stdlib

Problem

ReflectionMethod (and ReflectionFunctionAbstract) must expose typed-return introspection per PHP 8+. This compiler implements getParameters() / getAttributes() but getReturnType(), isDeprecated(), and hasTentativeReturnType() are undefined — framework code using return-type reflection fails.

Pairs #5141 (hasReturnType() boolean probe) and #6594 (ReflectionType abstract hierarchy).

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\"); var_export(\$m->getReturnType()?->getName());"
php -r "class T{function f(): int{}} \$m=new ReflectionMethod(T::class,\"f\"); var_export(\$m->getReturnType()?->getName());"
'
Runtime Result
Zend PHP 8.2 'int'
bin/vm.php Call to undefined method ReflectionMethod::getReturnType()

Additional probes:

#[\Deprecated] class D { function f() {} }
(new ReflectionMethod(D::class, 'f'))->isDeprecated(); // Zend: true

class Tentative { function f(): int {} } // PHP 8.1 tentative on inherited — use fixture from php-src tests

Scope (this repo)

Component Path
Metadata lib/VM/ReflectionSupport.php, compile-time return type storage on ClassMethod
VM methods lib/VM/Builtin/ReflectionMethodGetReturnType.php (new), register in BuiltinClasses.php
Return type objects #6594 — must return ReflectionNamedType / union / intersection extending ReflectionType
Compliance test/compliance/cases/stdlib/reflection_method_get_return_type.phpt

PHP-in-PHP: implement in lib/VM/ + ext/standard/VmReflection.php; no C runtime.

Done when

  • Repro prints 'int' for : int method; null for untyped legacy method
  • isDeprecated() matches #[\Deprecated] attribute on method/class (php-src rules)
  • hasTentativeReturnType() matches Zend on inherited tentative fixtures
  • No undefined-method fatals for the three APIs on VM
  • JIT/AOT: VM-only v1 documented in capability matrix

Strictness: php-src-strict

Related

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