Skip to content

Commit c200623

Browse files
committed
Merge branch 'PHP-8.2'
* PHP-8.2: Private method incorrectly marked as "overwrites" in reflection
2 parents e423cfb + a85c757 commit c200623

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

ext/reflection/php_reflection.c

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

ext/reflection/tests/ReflectionClass_toString_003.phpt

Lines changed: 2 additions & 2 deletions
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

Lines changed: 24 additions & 0 deletions
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)