xref: /PHP-7.2/ext/reflection/tests/bug66430.phpt (revision 17ccbeec)
1--TEST--
2Bug #66430: ReflectionFunction::invoke does not invoke closure with object scope
3--FILE--
4<?php
5
6class Alpha {
7	public $message = "Valid representation";
8
9	public function bravo() {
10		return $this->message;
11	}
12}
13
14$alpha = new Alpha();
15
16echo "alpha.bravo:                   ", $alpha->bravo().PHP_EOL;
17
18$reflection = new ReflectionObject($alpha);
19
20$method = $reflection->getMethod("bravo");
21$closure = $method->getClosure($alpha);
22
23$reflectionC = new ReflectionFunction($closure);
24
25echo "reflection of alpha.bravo:     ", $method->invoke($alpha).PHP_EOL;
26echo "closure of alpha.bravo:        ", $closure().PHP_EOL;
27echo "call_user_func of closure:     ", call_user_func($closure).PHP_EOL;
28echo PHP_EOL;
29echo "closure cl of c(alpha.bravo):  ", get_class($reflectionC->getClosureThis()).PHP_EOL;
30echo "scope cl of c(alpha.bravo):    ", $reflectionC->getClosureScopeClass()->getName().PHP_EOL;
31echo "reflection of c(alpha.bravo):  ", $reflectionC->invoke().PHP_EOL;
32
33?>
34--EXPECT--
35alpha.bravo:                   Valid representation
36reflection of alpha.bravo:     Valid representation
37closure of alpha.bravo:        Valid representation
38call_user_func of closure:     Valid representation
39
40closure cl of c(alpha.bravo):  Alpha
41scope cl of c(alpha.bravo):    Alpha
42reflection of c(alpha.bravo):  Valid representation
43