1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00
There were 4 different reports of this breaking behavior. This is higher than I
expected. This bug fix may still be desirable, but should be discussed on the
list beforehand.

Closes GH-12127
This commit is contained in:
Ilija Tovilo
2023-09-05 10:37:47 +02:00
parent 8a392eddf9
commit 3433dab5f7
2 changed files with 20 additions and 10 deletions

View File

@@ -3272,9 +3272,7 @@ static void instantiate_reflection_method(INTERNAL_FUNCTION_PARAMETERS, bool is_
&& (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
|| ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) && mptr->common.scope != ce))
{
} else if ((mptr = zend_hash_str_find_ptr(&ce->function_table, lcname, method_name_len)) == NULL) {
efree(lcname);
zend_throw_exception_ex(reflection_exception_ptr, 0,
"Method %s::%s() does not exist", ZSTR_VAL(ce->name), method_name);

View File

@@ -1,5 +1,5 @@
--TEST--
GH-9470: ReflectionMethod constructor should not find private parent method
GH-9470: ReflectionMethod constructor finds private parent method
--FILE--
<?php
@@ -13,11 +13,12 @@ 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";
}
echo (string) new ReflectionMethod('B', 'privateMethod');
$r = new ReflectionClass('B');
echo (string) $r->getMethod('publicMethod');
echo (string) $r->getMethod('protectedMethod');
echo (string) $r->getMethod('privateMethod');
?>
--EXPECTF--
@@ -27,4 +28,15 @@ Method [ <user, inherits A> public method publicMethod ] {
Method [ <user, inherits A> protected method protectedMethod ] {
@@ %s 6 - 6
}
Method B::privateMethod() does not exist
Method [ <user, inherits A> private method privateMethod ] {
@@ %s 7 - 7
}
Method [ <user, inherits A> public method publicMethod ] {
@@ %s 5 - 5
}
Method [ <user, inherits A> protected method protectedMethod ] {
@@ %s 6 - 6
}
Method [ <user, inherits A> private method privateMethod ] {
@@ %s 7 - 7
}