Skip to content

Throw in ReflectionMethod::__construct() when initialized with private parent method #9640

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
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@ PHP NEWS
. Added pdeathsig to builtin server to terminate workers when the master
process is killed. (ilutov)

- 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! >>>
4 changes: 3 additions & 1 deletion ext/reflection/php_reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
30 changes: 30 additions & 0 deletions ext/reflection/tests/gh9470.phpt
Original file line number Diff line number Diff line change
@@ -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