Skip to content

Commit 1435fc6

Browse files
committed
Private method incorrectly marked as "overwrites" in reflection
Fix phpGH-9409 Closes phpGH-9469
1 parent 6ac3f7c commit 1435fc6

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ PHP NEWS
2525
- Reflection:
2626
. Fixed bug GH-8932 (ReflectionFunction provides no way to get the called
2727
class of a Closure). (cmb, Nicolas Grekas)
28+
. Fixed bug GH-9409 (Private method is incorrectly dumped as "overwrites").
29+
(ilutov)
2830

2931
- Streams:
3032
. Fixed bug GH-9316 ($http_response_header is wrong for long status line).

ext/reflection/php_reflection.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ static void _function_string(smart_str *str, zend_function *fptr, zend_class_ent
784784
} else if (fptr->common.scope->parent) {
785785
lc_name = zend_string_tolower(fptr->common.function_name);
786786
if ((overwrites = zend_hash_find_ptr(&fptr->common.scope->parent->function_table, lc_name)) != NULL) {
787-
if (fptr->common.scope != overwrites->common.scope) {
787+
if (fptr->common.scope != overwrites->common.scope && !(overwrites->common.fn_flags & ZEND_ACC_PRIVATE)) {
788788
smart_str_append_printf(str, ", overwrites %s", ZSTR_VAL(overwrites->common.scope->name));
789789
}
790790
}

ext/reflection/tests/ReflectionClass_toString_003.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Class [ <user> class B extends A ] {
6666
}
6767

6868
- Methods [1] {
69-
Method [ <user, overwrites A> private method f ] {
69+
Method [ <user> private method f ] {
7070
@@ %s 6 - 6
7171
}
7272
}
@@ -111,7 +111,7 @@ Class [ <user> class D extends C ] {
111111
}
112112

113113
- Methods [1] {
114-
Method [ <user, overwrites B> private method f ] {
114+
Method [ <user> private method f ] {
115115
@@ %s 12 - 12
116116
}
117117
}

ext/reflection/tests/gh9409.phpt

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
GH-9409: Private method is incorrectly dumped as "overwrites"
3+
--FILE--
4+
<?php
5+
6+
class A {
7+
private function privateMethod() {}
8+
}
9+
10+
class C extends A {
11+
private function privateMethod() {}
12+
}
13+
14+
echo (new ReflectionClass('A'))->getMethod('privateMethod');
15+
echo (new ReflectionClass('C'))->getMethod('privateMethod');
16+
17+
?>
18+
--EXPECTF--
19+
Method [ <user> private method privateMethod ] {
20+
@@ %s %d - %d
21+
}
22+
Method [ <user> private method privateMethod ] {
23+
@@ %s %d - %d
24+
}

0 commit comments

Comments
 (0)