Skip to content

Stdlib: ReflectionMethod::createFromClosure() / ReflectionFunction::createFromCallable() — static factories missing (php_reflection.c) #7039

@PurHur

Description

@PurHur

Category

stdlib / reflection (php-src-strict)

Problem

PHP 8.1+ reflection factories for closures/callables are missing:

  • ReflectionFunction::createFromCallable(callable $callback)
  • ReflectionMethod::createFromClosure(Closure $closure, ?string $scope = null, ?string $name = null)

Without these, introspection of first-class callables and Closure objects cannot match Zend tooling.

php-src reference

Repro

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php -r "var_dump(method_exists(\"ReflectionFunction\", \"createFromCallable\"));"  # false
php bin/vm.php -r "var_dump(method_exists(\"ReflectionMethod\", \"createFromClosure\"));"    # false
php bin/vm.php test/repro/maintainer_reflection_create_from_callable.php                      # Error: missing
php -r "\$fn = fn() => 42; echo ReflectionFunction::createFromCallable(\$fn)->invoke();"       # Zend: 42
'

Scope (this repo)

Path Work
Reflection builtin handlers Register both static factories
lib/VM/ Map Closure/callable zvals to reflection objects
Tests compliance .phpt for closure + invokable object callbacks

Implement in ext/ + lib/VM/ — reuse existing ReflectionFunction/ReflectionMethod classes.

Done when

  • Both methods exist and repro prints 42
  • Invalid/non-closure callables throw ReflectionException/TypeError per Zend
  • createFromClosure honors optional $scope / $name for bound closures

Related

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