diff --git a/NEWS b/NEWS index 383facfd527..1322257293c 100644 --- a/NEWS +++ b/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! >>> diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index b49ee57ba5f..186a240b4a0 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -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); diff --git a/ext/reflection/tests/gh9470.phpt b/ext/reflection/tests/gh9470.phpt new file mode 100644 index 00000000000..d5cda82add7 --- /dev/null +++ b/ext/reflection/tests/gh9470.phpt @@ -0,0 +1,30 @@ +--TEST-- +GH-9470: ReflectionMethod constructor should not find private parent method +--FILE-- +getMessage(), "\n"; +} + +?> +--EXPECTF-- +Method [ public method publicMethod ] { + @@ %s 5 - 5 +} +Method [ protected method protectedMethod ] { + @@ %s 6 - 6 +} +Method B::privateMethod() does not exist