Skip to content

Commit a795f3e

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Private method incorrectly marked as "overwrites" in reflection
2 parents b5cad50 + 1435fc6 commit a795f3e

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

ext/reflection/php_reflection.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ static void _function_string(smart_str *str, zend_function *fptr, zend_class_ent
793793
} else if (fptr->common.scope->parent) {
794794
lc_name = zend_string_tolower(fptr->common.function_name);
795795
if ((overwrites = zend_hash_find_ptr(&fptr->common.scope->parent->function_table, lc_name)) != NULL) {
796-
if (fptr->common.scope != overwrites->common.scope) {
796+
if (fptr->common.scope != overwrites->common.scope && !(overwrites->common.fn_flags & ZEND_ACC_PRIVATE)) {
797797
smart_str_append_printf(str, ", overwrites %s", ZSTR_VAL(overwrites->common.scope->name));
798798
}
799799
}

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)