mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Throw in ReflectionMethod::__construct() when initialized with private parent method
Fixes GH-9470 Closes GH-9640
This commit is contained in:
parent
08e886235a
commit
e186765a4d
3 changed files with 37 additions and 1 deletions
4
NEWS
4
NEWS
|
@ -34,4 +34,8 @@ PHP NEWS
|
|||
. Added SO_ATTACH_REUSEPORT_CBPF socket option, to give tighter control
|
||||
over socket binding for a cpu core. (David Carlier)
|
||||
|
||||
- Reflection:
|
||||
. Fix GH-9470 (ReflectionMethod constructor should not find private parent
|
||||
method). (ilutov)
|
||||
|
||||
<<< NOTE: Insert NEWS from last stable release here prior to actual release! >>>
|
||||
|
|
|
@ -3281,7 +3281,9 @@ ZEND_METHOD(ReflectionMethod, __construct)
|
|||
&& (mptr = zend_get_closure_invoke_method(orig_obj)) != NULL)
|
||||
{
|
||||
/* do nothing, mptr already set */
|
||||
} else if ((mptr = zend_hash_str_find_ptr(&ce->function_table, lcname, method_name_len)) == NULL) {
|
||||
} else if ((mptr = zend_hash_str_find_ptr(&ce->function_table, lcname, method_name_len)) == NULL
|
||||
|| ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) && mptr->common.scope != ce))
|
||||
{
|
||||
efree(lcname);
|
||||
zend_throw_exception_ex(reflection_exception_ptr, 0,
|
||||
"Method %s::%s() does not exist", ZSTR_VAL(ce->name), method_name);
|
||||
|
|
30
ext/reflection/tests/gh9470.phpt
Normal file
30
ext/reflection/tests/gh9470.phpt
Normal file
|
@ -0,0 +1,30 @@
|
|||
--TEST--
|
||||
GH-9470: ReflectionMethod constructor should not find private parent method
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
class A
|
||||
{
|
||||
public function publicMethod() {}
|
||||
protected function protectedMethod() {}
|
||||
private function privateMethod() {}
|
||||
}
|
||||
class B extends A {}
|
||||
|
||||
echo (string) new ReflectionMethod('B', 'publicMethod');
|
||||
echo (string) new ReflectionMethod('B', 'protectedMethod');
|
||||
try {
|
||||
echo (string) new ReflectionMethod('B', 'privateMethod');
|
||||
} catch(Throwable $e){
|
||||
echo $e->getMessage(), "\n";
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Method [ <user, inherits A> public method publicMethod ] {
|
||||
@@ %s 5 - 5
|
||||
}
|
||||
Method [ <user, inherits A> protected method protectedMethod ] {
|
||||
@@ %s 6 - 6
|
||||
}
|
||||
Method B::privateMethod() does not exist
|
Loading…
Add table
Add a link
Reference in a new issue