From e7b16821d73602e9824146b0490f5447153b76c8 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Wed, 17 Apr 2024 15:03:13 +0100 Subject: [PATCH] ext/reflection: Add test for ReflectionParameter::getDeclaringFunction() with a ReflectionMethod creation from a Closure --- .../closures_bound_getDeclaringFunction.phpt | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 ext/reflection/tests/closures_bound_getDeclaringFunction.phpt diff --git a/ext/reflection/tests/closures_bound_getDeclaringFunction.phpt b/ext/reflection/tests/closures_bound_getDeclaringFunction.phpt new file mode 100644 index 000000000000..98149951b6e7 --- /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-- +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