From 1435fc6262749d3f9861ef41a3d63825bac8ca2c Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Fri, 2 Sep 2022 16:12:38 +0200 Subject: [PATCH] Private method incorrectly marked as "overwrites" in reflection Fix GH-9409 Closes GH-9469 --- NEWS | 2 ++ ext/reflection/php_reflection.c | 2 +- .../tests/ReflectionClass_toString_003.phpt | 4 ++-- ext/reflection/tests/gh9409.phpt | 24 +++++++++++++++++++ 4 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 ext/reflection/tests/gh9409.phpt diff --git a/NEWS b/NEWS index 3e85f1483ec..cbf0dd418bd 100644 --- a/NEWS +++ b/NEWS @@ -25,6 +25,8 @@ PHP NEWS - Reflection: . Fixed bug GH-8932 (ReflectionFunction provides no way to get the called class of a Closure). (cmb, Nicolas Grekas) + . Fixed bug GH-9409 (Private method is incorrectly dumped as "overwrites"). + (ilutov) - Streams: . Fixed bug GH-9316 ($http_response_header is wrong for long status line). diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index ae5b0f1ac24..de3c9602fd3 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -784,7 +784,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 +}