Skip to content

Private method incorrectly marked as "overwrites" in reflection #9469

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
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
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ PHP NEWS
(cmb)
. Fixed bug GH-8421 (Closures should accept attributes with
Attribute::TARGET_FUNCTION). (ollieread)
. Fixed bug GH-9409 (Private method is incorrectly dumped as "overwrites").
(ilutov)

- Zlib:
. Fixed bug GH-7953 (ob_clean() only does not set Content-Encoding). (cmb)
Expand Down
2 changes: 1 addition & 1 deletion ext/reflection/php_reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Expand Down
4 changes: 2 additions & 2 deletions ext/reflection/tests/ReflectionClass_toString_003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Class [ <user> class B extends A ] {
}

- Methods [1] {
Method [ <user, overwrites A> private method f ] {
Method [ <user> private method f ] {
@@ %s 6 - 6
}
}
Expand Down Expand Up @@ -111,7 +111,7 @@ Class [ <user> class D extends C ] {
}

- Methods [1] {
Method [ <user, overwrites B> private method f ] {
Method [ <user> private method f ] {
@@ %s 12 - 12
}
}
Expand Down
24 changes: 24 additions & 0 deletions ext/reflection/tests/gh9409.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
GH-9409: Private method is incorrectly dumped as "overwrites"
--FILE--
<?php

class A {
private function privateMethod() {}
}

class C extends A {
private function privateMethod() {}
}

echo (new ReflectionClass('A'))->getMethod('privateMethod');
echo (new ReflectionClass('C'))->getMethod('privateMethod');

?>
--EXPECTF--
Method [ <user> private method privateMethod ] {
@@ %s %d - %d
}
Method [ <user> private method privateMethod ] {
@@ %s %d - %d
}