Skip to content

Commit 87bc994

Browse files
committed
Fixed bug #64592
Make ReflectionClass::getMethods() behave the same ways as ReflectionClass::getProperties() by not including private methods from parent classes.
1 parent b314603 commit 87bc994

File tree

4 files changed

+8
-20
lines changed

4 files changed

+8
-20
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ PHP NEWS
8585
message with traits). (villfa)
8686
. Implement ReflectionProperty::hasDefaultValue and
8787
Reflection::getDefaultValue (beberlei)
88+
. Fixed bug #64592 (ReflectionClass::getMethods() returns methods out of
89+
scope). (Nikita)
8890

8991
- Session:
9092
. Fixed bug #78624 (session_gc return value for user defined session

ext/reflection/php_reflection.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4056,6 +4056,10 @@ ZEND_METHOD(reflection_class, getMethod)
40564056
/* {{{ _addmethod */
40574057
static void _addmethod(zend_function *mptr, zend_class_entry *ce, zval *retval, zend_long filter)
40584058
{
4059+
if ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) && mptr->common.scope != ce) {
4060+
return;
4061+
}
4062+
40594063
if (mptr->common.fn_flags & filter) {
40604064
zval method;
40614065
reflection_method_factory(ce, mptr, NULL, &method);

ext/reflection/tests/ReflectionClass_getMethods_001.phpt

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,5 @@ array(2) {
122122
}
123123
}
124124
Reflecting on class subprivf:
125-
array(2) {
126-
[0]=>
127-
object(ReflectionMethod)#%d (2) {
128-
["name"]=>
129-
string(1) "f"
130-
["class"]=>
131-
string(5) "privf"
132-
}
133-
[1]=>
134-
object(ReflectionMethod)#%d (2) {
135-
["name"]=>
136-
string(1) "s"
137-
["class"]=>
138-
string(5) "privf"
139-
}
125+
array(0) {
140126
}

ext/reflection/tests/ReflectionMethod_getModifiers_basic.phpt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ echo "ReflectionMethod::getModifiers() modifiers:\n";
8181
printf("0x%08x\n", $a->getModifiers());
8282

8383
?>
84-
--EXPECTF--
84+
--EXPECT--
8585
Modifiers for method TestClass::foo():
8686
0x00000001
8787

@@ -158,10 +158,6 @@ Modifiers for method TestClass::stat():
158158
0x00000011
159159

160160

161-
Modifiers for method TestClass::priv():
162-
0x00000004
163-
164-
165161
Modifiers for method TestClass::prot():
166162
0x00000002
167163

0 commit comments

Comments
 (0)