Skip to content

Commit 3433dab

Browse files
committed
Revert 479e659
There were 4 different reports of this breaking behavior. This is higher than I expected. This bug fix may still be desirable, but should be discussed on the list beforehand. Closes GH-12127
1 parent 8a392ed commit 3433dab

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

ext/reflection/php_reflection.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3272,9 +3272,7 @@ static void instantiate_reflection_method(INTERNAL_FUNCTION_PARAMETERS, bool is_
32723272
&& (mptr = zend_get_closure_invoke_method(orig_obj)) != NULL)
32733273
{
32743274
/* do nothing, mptr already set */
3275-
} else if ((mptr = zend_hash_str_find_ptr(&ce->function_table, lcname, method_name_len)) == NULL
3276-
|| ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) && mptr->common.scope != ce))
3277-
{
3275+
} else if ((mptr = zend_hash_str_find_ptr(&ce->function_table, lcname, method_name_len)) == NULL) {
32783276
efree(lcname);
32793277
zend_throw_exception_ex(reflection_exception_ptr, 0,
32803278
"Method %s::%s() does not exist", ZSTR_VAL(ce->name), method_name);

ext/reflection/tests/gh9470.phpt

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
GH-9470: ReflectionMethod constructor should not find private parent method
2+
GH-9470: ReflectionMethod constructor finds private parent method
33
--FILE--
44
<?php
55

@@ -13,11 +13,12 @@ class B extends A {}
1313

1414
echo (string) new ReflectionMethod('B', 'publicMethod');
1515
echo (string) new ReflectionMethod('B', 'protectedMethod');
16-
try {
17-
echo (string) new ReflectionMethod('B', 'privateMethod');
18-
} catch(Throwable $e){
19-
echo $e->getMessage(), "\n";
20-
}
16+
echo (string) new ReflectionMethod('B', 'privateMethod');
17+
18+
$r = new ReflectionClass('B');
19+
echo (string) $r->getMethod('publicMethod');
20+
echo (string) $r->getMethod('protectedMethod');
21+
echo (string) $r->getMethod('privateMethod');
2122

2223
?>
2324
--EXPECTF--
@@ -27,4 +28,15 @@ Method [ <user, inherits A> public method publicMethod ] {
2728
Method [ <user, inherits A> protected method protectedMethod ] {
2829
@@ %s 6 - 6
2930
}
30-
Method B::privateMethod() does not exist
31+
Method [ <user, inherits A> private method privateMethod ] {
32+
@@ %s 7 - 7
33+
}
34+
Method [ <user, inherits A> public method publicMethod ] {
35+
@@ %s 5 - 5
36+
}
37+
Method [ <user, inherits A> protected method protectedMethod ] {
38+
@@ %s 6 - 6
39+
}
40+
Method [ <user, inherits A> private method privateMethod ] {
41+
@@ %s 7 - 7
42+
}

0 commit comments

Comments
 (0)