diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 4c28c087b61..b49ee57ba5f 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -792,7 +792,7 @@ static void _function_string(smart_str *str, zend_function *fptr, zend_class_ent } else if (fptr->common.scope->parent) { lc_name = zend_string_tolower(fptr->common.function_name); if ((overwrites = zend_hash_find_ptr(&fptr->common.scope->parent->function_table, lc_name)) != NULL) { - if (fptr->common.scope != overwrites->common.scope) { + if (fptr->common.scope != overwrites->common.scope && !(overwrites->common.fn_flags & ZEND_ACC_PRIVATE)) { smart_str_append_printf(str, ", overwrites %s", ZSTR_VAL(overwrites->common.scope->name)); } } diff --git a/ext/reflection/tests/ReflectionClass_toString_003.phpt b/ext/reflection/tests/ReflectionClass_toString_003.phpt index a67d0bfac5f..4d488325eeb 100644 --- a/ext/reflection/tests/ReflectionClass_toString_003.phpt +++ b/ext/reflection/tests/ReflectionClass_toString_003.phpt @@ -66,7 +66,7 @@ Class [ class B extends A ] { } - Methods [1] { - Method [ private method f ] { + Method [ private method f ] { @@ %s 6 - 6 } } @@ -111,7 +111,7 @@ Class [ class D extends C ] { } - Methods [1] { - Method [ private method f ] { + Method [ private method f ] { @@ %s 12 - 12 } } diff --git a/ext/reflection/tests/gh9409.phpt b/ext/reflection/tests/gh9409.phpt new file mode 100644 index 00000000000..a10e7b5303a --- /dev/null +++ b/ext/reflection/tests/gh9409.phpt @@ -0,0 +1,24 @@ +--TEST-- +GH-9409: Private method is incorrectly dumped as "overwrites" +--FILE-- +getMethod('privateMethod'); +echo (new ReflectionClass('C'))->getMethod('privateMethod'); + +?> +--EXPECTF-- +Method [ private method privateMethod ] { + @@ %s %d - %d +} +Method [ private method privateMethod ] { + @@ %s %d - %d +}