[php-src] master: ext/reflection: Add test for ReflectionParameter::getDeclaringFunction() with a ReflectionMethod creation from a Closure (#13987)

From: Date: Wed, 17 Apr 2024 19:36:24 +0000
Subject: [php-src] master: ext/reflection: Add test for ReflectionParameter::getDeclaringFunction() with a ReflectionMethod creation from a Closure (#13987)
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-128148@lists.php.net to get a copy of this message
Author: Gina Peter Banyard (Girgias) Committer: GitHub (web-flow) Pusher: Girgias Date: 2024-04-17T20:36:17+01:00 Commit: https://github.com/php/php-src/commit/1f8c899dcb45f5701f51b3747646ea416b99383f Raw diff: https://github.com/php/php-src/commit/1f8c899dcb45f5701f51b3747646ea416b99383f.diff ext/reflection: Add test for ReflectionParameter::getDeclaringFunction() with a ReflectionMethod creation from a Closure (#13987) Changed paths: A ext/reflection/tests/closures_bound_getDeclaringFunction.phpt Diff: diff --git a/ext/reflection/tests/closures_bound_getDeclaringFunction.phpt b/ext/reflection/tests/closures_bound_getDeclaringFunction.phpt new file mode 100644 index 0000000000000..98149951b6e78 --- /dev/null +++ b/ext/reflection/tests/closures_bound_getDeclaringFunction.phpt @@ -0,0 +1,43 @@ +--TEST-- +Closures via getParameters() and getDeclaringFunction() calling reflection_method_factory() with an internal object being set +--FILE-- +<?php + +class A {} +class B extends A {} + +$closure = function($op1, $op2 = 0): self { }; + +$b = new B(); +$fn = $closure->bindTo($b, B::class); + +const CLOSURE_NAME = '{closure:' . __FILE__ . ':6}'; + +$rClosure = new ReflectionFunction($fn); +var_dump($rClosure->name == CLOSURE_NAME); + +$params = $rClosure->getParameters(); +unset ($rClosure); +$closureFromParam = $params[0]->getDeclaringFunction(); +var_dump($closureFromParam::class); +var_dump($closureFromParam->name == CLOSURE_NAME); + +$rClass = new ReflectionClass($b); +$rMethods = $rClass->getMethods(); +var_dump($rMethods); + +try { + $rMethod = new ReflectionMethod($b, CLOSURE_NAME); + var_dump($rMethod); +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +?> +--EXPECTF-- +bool(true) +string(16) "ReflectionMethod" +bool(true) +array(0) { +} +ReflectionException: Method B::{closure:%s:6}() does not exist

« previous php.cvs (#128148) next »