File tree Expand file tree Collapse file tree 3 files changed +36
-1
lines changed
Expand file tree Collapse file tree 3 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -21,5 +21,8 @@ PHP NEWS
2121 . Added pdeathsig to builtin server to terminate workers when the master
2222 process is killed. (ilutov)
2323
24+ - Reflection:
25+ . Fix GH-9470 (ReflectionMethod constructor should not find private parent
26+ method). (ilutov)
2427
2528<<< 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)
32813281 && (mptr = zend_get_closure_invoke_method (orig_obj )) != NULL )
32823282 {
32833283 /* 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+ {
32853287 efree (lcname );
32863288 zend_throw_exception_ex (reflection_exception_ptr , 0 ,
32873289 "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