File tree Expand file tree Collapse file tree 3 files changed +54
-0
lines changed Expand file tree Collapse file tree 3 files changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ PHP NEWS
10
10
- Reflection:
11
11
. Fixed bug #76936 (Objects cannot access their private attributes while
12
12
handling reflection errors). (Nikita)
13
+ . Fixed bug #66430 (ReflectionFunction::invoke does not invoke closure with
14
+ object scope). (Nikita)
13
15
14
16
11 Oct 2018, PHP 7.2.11
15
17
Original file line number Diff line number Diff line change @@ -1897,6 +1897,11 @@ ZEND_METHOD(reflection_function, invoke)
1897
1897
fcc .called_scope = NULL ;
1898
1898
fcc .object = NULL ;
1899
1899
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
+
1900
1905
result = zend_call_function (& fci , & fcc );
1901
1906
1902
1907
if (result == FAILURE ) {
@@ -1958,6 +1963,11 @@ ZEND_METHOD(reflection_function, invokeArgs)
1958
1963
fcc .called_scope = NULL ;
1959
1964
fcc .object = NULL ;
1960
1965
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
+
1961
1971
result = zend_call_function (& fci , & fcc );
1962
1972
1963
1973
for (i = 0 ; i < argc ; i ++ ) {
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments