Skip to content

Commit 1f8c899

Browse files
authored
ext/reflection: Add test for ReflectionParameter::getDeclaringFunction() with a ReflectionMethod creation from a Closure (#13987)
1 parent 47ec320 commit 1f8c899

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
--TEST--
2+
Closures via getParameters() and getDeclaringFunction() calling reflection_method_factory() with an internal object being set
3+
--FILE--
4+
<?php
5+
6+
class A {}
7+
class B extends A {}
8+
9+
$closure = function($op1, $op2 = 0): self { };
10+
11+
$b = new B();
12+
$fn = $closure->bindTo($b, B::class);
13+
14+
const CLOSURE_NAME = '{closure:' . __FILE__ . ':6}';
15+
16+
$rClosure = new ReflectionFunction($fn);
17+
var_dump($rClosure->name == CLOSURE_NAME);
18+
19+
$params = $rClosure->getParameters();
20+
unset ($rClosure);
21+
$closureFromParam = $params[0]->getDeclaringFunction();
22+
var_dump($closureFromParam::class);
23+
var_dump($closureFromParam->name == CLOSURE_NAME);
24+
25+
$rClass = new ReflectionClass($b);
26+
$rMethods = $rClass->getMethods();
27+
var_dump($rMethods);
28+
29+
try {
30+
$rMethod = new ReflectionMethod($b, CLOSURE_NAME);
31+
var_dump($rMethod);
32+
} catch (\Throwable $e) {
33+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
34+
}
35+
36+
?>
37+
--EXPECTF--
38+
bool(true)
39+
string(16) "ReflectionMethod"
40+
bool(true)
41+
array(0) {
42+
}
43+
ReflectionException: Method B::{closure:%s:6}() does not exist

0 commit comments

Comments
 (0)