Skip to content

Revert 479e659 #12127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions ext/reflection/php_reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
26 changes: 19 additions & 7 deletions ext/reflection/tests/gh9470.phpt
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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--
Expand All @@ -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
}