File tree 3 files changed +36
-1
lines changed
3 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -21,5 +21,8 @@ PHP NEWS
21
21
. Added pdeathsig to builtin server to terminate workers when the master
22
22
process is killed. (ilutov)
23
23
24
+ - Reflection:
25
+ . Fix GH-9470 (ReflectionMethod constructor should not find private parent
26
+ method). (ilutov)
24
27
25
28
<<< NOTE: Insert NEWS from last stable release here prior to actual release! >>>
Original file line number Diff line number Diff line change @@ -3281,7 +3281,9 @@ ZEND_METHOD(ReflectionMethod, __construct)
3281
3281
&& (mptr = zend_get_closure_invoke_method (orig_obj )) != NULL )
3282
3282
{
3283
3283
/* do nothing, mptr already set */
3284
- } else if ((mptr = zend_hash_str_find_ptr (& ce -> function_table , lcname , method_name_len )) == NULL ) {
3284
+ } else if ((mptr = zend_hash_str_find_ptr (& ce -> function_table , lcname , method_name_len )) == NULL
3285
+ || ((mptr -> common .fn_flags & ZEND_ACC_PRIVATE ) && mptr -> common .scope != ce ))
3286
+ {
3285
3287
efree (lcname );
3286
3288
zend_throw_exception_ex (reflection_exception_ptr , 0 ,
3287
3289
"Method %s::%s() does not exist" , ZSTR_VAL (ce -> name ), method_name );
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ GH-9470: ReflectionMethod constructor should not find private parent method
3
+ --FILE--
4
+ <?php
5
+
6
+ class A
7
+ {
8
+ public function publicMethod () {}
9
+ protected function protectedMethod () {}
10
+ private function privateMethod () {}
11
+ }
12
+ class B extends A {}
13
+
14
+ echo (string ) new ReflectionMethod ('B ' , 'publicMethod ' );
15
+ echo (string ) new ReflectionMethod ('B ' , 'protectedMethod ' );
16
+ try {
17
+ echo (string ) new ReflectionMethod ('B ' , 'privateMethod ' );
18
+ } catch (Throwable $ e ){
19
+ echo $ e ->getMessage (), "\n" ;
20
+ }
21
+
22
+ ?>
23
+ --EXPECTF--
24
+ Method [ <user, inherits A> public method publicMethod ] {
25
+ @@ %s 5 - 5
26
+ }
27
+ Method [ <user, inherits A> protected method protectedMethod ] {
28
+ @@ %s 6 - 6
29
+ }
30
+ Method B::privateMethod() does not exist
You can’t perform that action at this time.
0 commit comments