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 @@ -15,6 +15,8 @@ PHP NEWS
15
15
- Reflection:
16
16
. Fixed bug #76936 (Objects cannot access their private attributes while
17
17
handling reflection errors). (Nikita)
18
+ . Fixed bug #66430 (ReflectionFunction::invoke does not invoke closure with
19
+ object scope). (Nikita)
18
20
19
21
27 Sep 2018, PHP 7.3.0RC2
20
22
Original file line number Diff line number Diff line change @@ -1862,6 +1862,11 @@ ZEND_METHOD(reflection_function, invoke)
1862
1862
fcc .called_scope = NULL ;
1863
1863
fcc .object = NULL ;
1864
1864
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
+
1865
1870
result = zend_call_function (& fci , & fcc );
1866
1871
1867
1872
if (result == FAILURE ) {
@@ -1920,6 +1925,11 @@ ZEND_METHOD(reflection_function, invokeArgs)
1920
1925
fcc .called_scope = NULL ;
1921
1926
fcc .object = NULL ;
1922
1927
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
+
1923
1933
result = zend_call_function (& fci , & fcc );
1924
1934
1925
1935
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