From 87bc99439d5cdd3465ae37f1207067fc40ab7b19 Mon Sep 17 00:00:00 2001 From: Nikita Popov <nikita.ppv@gmail.com> Date: Fri, 28 Feb 2020 15:53:04 +0100 Subject: [PATCH] Fixed bug #64592 Make ReflectionClass::getMethods() behave the same ways as ReflectionClass::getProperties() by not including private methods from parent classes. --- NEWS | 2 ++ ext/reflection/php_reflection.c | 4 ++++ .../tests/ReflectionClass_getMethods_001.phpt | 16 +--------------- .../ReflectionMethod_getModifiers_basic.phpt | 6 +----- 4 files changed, 8 insertions(+), 20 deletions(-) diff --git a/NEWS b/NEWS index f9a3a46761..632383ed70 100644 --- a/NEWS +++ b/NEWS @@ -85,6 +85,8 @@ PHP NEWS message with traits). (villfa) . Implement ReflectionProperty::hasDefaultValue and Reflection::getDefaultValue (beberlei) + . Fixed bug #64592 (ReflectionClass::getMethods() returns methods out of + scope). (Nikita) - Session: . Fixed bug #78624 (session_gc return value for user defined session diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 101913c494..628d4f30ac 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -4056,6 +4056,10 @@ ZEND_METHOD(reflection_class, getMethod) /* {{{ _addmethod */ static void _addmethod(zend_function *mptr, zend_class_entry *ce, zval *retval, zend_long filter) { + if ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) && mptr->common.scope != ce) { + return; + } + if (mptr->common.fn_flags & filter) { zval method; reflection_method_factory(ce, mptr, NULL, &method); diff --git a/ext/reflection/tests/ReflectionClass_getMethods_001.phpt b/ext/reflection/tests/ReflectionClass_getMethods_001.phpt index 1f2ed55ffb..4e008e8710 100644 --- a/ext/reflection/tests/ReflectionClass_getMethods_001.phpt +++ b/ext/reflection/tests/ReflectionClass_getMethods_001.phpt @@ -122,19 +122,5 @@ array(2) { } } Reflecting on class subprivf: -array(2) { - [0]=> - object(ReflectionMethod)#%d (2) { - ["name"]=> - string(1) "f" - ["class"]=> - string(5) "privf" - } - [1]=> - object(ReflectionMethod)#%d (2) { - ["name"]=> - string(1) "s" - ["class"]=> - string(5) "privf" - } +array(0) { } diff --git a/ext/reflection/tests/ReflectionMethod_getModifiers_basic.phpt b/ext/reflection/tests/ReflectionMethod_getModifiers_basic.phpt index 00c1514fd9..70038c31a0 100644 --- a/ext/reflection/tests/ReflectionMethod_getModifiers_basic.phpt +++ b/ext/reflection/tests/ReflectionMethod_getModifiers_basic.phpt @@ -81,7 +81,7 @@ echo "ReflectionMethod::getModifiers() modifiers:\n"; printf("0x%08x\n", $a->getModifiers()); ?> ---EXPECTF-- +--EXPECT-- Modifiers for method TestClass::foo(): 0x00000001 @@ -158,10 +158,6 @@ Modifiers for method TestClass::stat(): 0x00000011 -Modifiers for method TestClass::priv(): -0x00000004 - - Modifiers for method TestClass::prot(): 0x00000002 -- 2.40.0