Skip to content

Commit a42801a

Browse files
committed
Merge branch 'PHP-7.2' into PHP-7.3
2 parents b839280 + f0647ed commit a42801a

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
@@ -15,6 +15,8 @@ PHP NEWS
1515
- Reflection:
1616
. Fixed bug #76936 (Objects cannot access their private attributes while
1717
handling reflection errors). (Nikita)
18+
. Fixed bug #66430 (ReflectionFunction::invoke does not invoke closure with
19+
object scope). (Nikita)
1820

1921
27 Sep 2018, PHP 7.3.0RC2
2022

ext/reflection/php_reflection.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,6 +1862,11 @@ ZEND_METHOD(reflection_function, invoke)
18621862
fcc.called_scope = NULL;
18631863
fcc.object = NULL;
18641864

1865+
if (!Z_ISUNDEF(intern->obj)) {
1866+
Z_OBJ_HT(intern->obj)->get_closure(
1867+
&intern->obj, &fcc.called_scope, &fcc.function_handler, &fcc.object);
1868+
}
1869+
18651870
result = zend_call_function(&fci, &fcc);
18661871

18671872
if (result == FAILURE) {
@@ -1920,6 +1925,11 @@ ZEND_METHOD(reflection_function, invokeArgs)
19201925
fcc.called_scope = NULL;
19211926
fcc.object = NULL;
19221927

1928+
if (!Z_ISUNDEF(intern->obj)) {
1929+
Z_OBJ_HT(intern->obj)->get_closure(
1930+
&intern->obj, &fcc.called_scope, &fcc.function_handler, &fcc.object);
1931+
}
1932+
19231933
result = zend_call_function(&fci, &fcc);
19241934

19251935
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)