Skip to content

Commit f0647ed

Browse files
committed
Fixed bug #66430
1 parent d2477b2 commit f0647ed

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ PHP NEWS
1010
- Reflection:
1111
. Fixed bug #76936 (Objects cannot access their private attributes while
1212
handling reflection errors). (Nikita)
13+
. Fixed bug #66430 (ReflectionFunction::invoke does not invoke closure with
14+
object scope). (Nikita)
1315

1416
11 Oct 2018, PHP 7.2.11
1517

ext/reflection/php_reflection.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,6 +1897,11 @@ ZEND_METHOD(reflection_function, invoke)
18971897
fcc.called_scope = NULL;
18981898
fcc.object = NULL;
18991899

1900+
if (!Z_ISUNDEF(intern->obj)) {
1901+
Z_OBJ_HT(intern->obj)->get_closure(
1902+
&intern->obj, &fcc.called_scope, &fcc.function_handler, &fcc.object);
1903+
}
1904+
19001905
result = zend_call_function(&fci, &fcc);
19011906

19021907
if (result == FAILURE) {
@@ -1958,6 +1963,11 @@ ZEND_METHOD(reflection_function, invokeArgs)
19581963
fcc.called_scope = NULL;
19591964
fcc.object = NULL;
19601965

1966+
if (!Z_ISUNDEF(intern->obj)) {
1967+
Z_OBJ_HT(intern->obj)->get_closure(
1968+
&intern->obj, &fcc.called_scope, &fcc.function_handler, &fcc.object);
1969+
}
1970+
19611971
result = zend_call_function(&fci, &fcc);
19621972

19631973
for (i = 0; i < argc; i++) {

ext/reflection/tests/bug66430.phpt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
--TEST--
2+
Bug #66430: ReflectionFunction::invoke does not invoke closure with object scope
3+
--FILE--
4+
<?php
5+
6+
class Alpha {
7+
public $message = "Valid representation";
8+
9+
public function bravo() {
10+
return $this->message;
11+
}
12+
}
13+
14+
$alpha = new Alpha();
15+
16+
echo "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+
25+
echo "reflection of alpha.bravo: ", $method->invoke($alpha).PHP_EOL;
26+
echo "closure of alpha.bravo: ", $closure().PHP_EOL;
27+
echo "call_user_func of closure: ", call_user_func($closure).PHP_EOL;
28+
echo PHP_EOL;
29+
echo "closure cl of c(alpha.bravo): ", get_class($reflectionC->getClosureThis()).PHP_EOL;
30+
echo "scope cl of c(alpha.bravo): ", $reflectionC->getClosureScopeClass()->getName().PHP_EOL;
31+
echo "reflection of c(alpha.bravo): ", $reflectionC->invoke().PHP_EOL;
32+
33+
?>
34+
--EXPECT--
35+
alpha.bravo: Valid representation
36+
reflection of alpha.bravo: Valid representation
37+
closure of alpha.bravo: Valid representation
38+
call_user_func of closure: Valid representation
39+
40+
closure cl of c(alpha.bravo): Alpha
41+
scope cl of c(alpha.bravo): Alpha
42+
reflection of c(alpha.bravo): Valid representation

0 commit comments

Comments
 (0)