From d47dc13042815e66ccd0410baebc2c5aa93651b8 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sat, 1 Aug 2009 20:44:00 +0000 Subject: [PATCH] - Fixed ReflectionClass::getStaticProperties() to do not return the private properties from parent class; behavior already adopted in ReflectionClass::getDefaultProperties() and ReflectionClass::getProperties(). --- ext/reflection/php_reflection.c | 15 +++++++++------ .../ReflectionClass_getDefaultProperties_001.phpt | 8 ++------ ...eflectionClass_setStaticPropertyValue_001.phpt | 4 ++-- ext/reflection/tests/bug49074.phpt | 6 +----- 4 files changed, 14 insertions(+), 19 deletions(-) diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 8f3e6be392..4f82b309a1 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -3216,13 +3216,16 @@ ZEND_METHOD(reflection_class, getStaticProperties) zend_u_unmangle_property_name(IS_UNICODE, key, key_len-1, &class_name, &prop_name); prop_name_len = u_strlen(prop_name.u); - /* copy: enforce read only access */ - ALLOC_ZVAL(prop_copy); - *prop_copy = **value; - zval_copy_ctor(prop_copy); - INIT_PZVAL(prop_copy); + /* filter privates from base classes */ + if (!(class_name.s && class_name.s[0] != '*' && u_strcmp(class_name.u, ce->name.u))) { + /* copy: enforce read only access */ + ALLOC_ZVAL(prop_copy); + *prop_copy = **value; + zval_copy_ctor(prop_copy); + INIT_PZVAL(prop_copy); - add_u_assoc_zval(return_value, IS_UNICODE, prop_name, prop_copy); + add_u_assoc_zval(return_value, IS_UNICODE, prop_name, prop_copy); + } } zend_hash_move_forward_ex(CE_STATIC_MEMBERS(ce), &pos); } diff --git a/ext/reflection/tests/ReflectionClass_getDefaultProperties_001.phpt b/ext/reflection/tests/ReflectionClass_getDefaultProperties_001.phpt index 3bf8f77ec6..e19db81188 100644 --- a/ext/reflection/tests/ReflectionClass_getDefaultProperties_001.phpt +++ b/ext/reflection/tests/ReflectionClass_getDefaultProperties_001.phpt @@ -109,13 +109,12 @@ Array ( [statPubC] => stat pubC in B [statProtC] => stat protC in B - [statPrivC] => stat privC in A + [statPrivC] => stat privC in B [statPubB] => stat pubB in B [statProtB] => stat protB in B [statPrivB] => stat privB in B [statPubA] => stat pubA in A [statProtA] => stat protA in A - [statPrivA] => stat privA in A ) @@ -146,13 +145,11 @@ Array ( [statPubC] => stat pubC in C [statProtC] => stat protC in C - [statPrivC] => stat privC in A + [statPrivC] => stat privC in C [statPubB] => stat pubB in B [statProtB] => stat protB in B - [statPrivB] => stat privB in B [statPubA] => stat pubA in A [statProtA] => stat protA in A - [statPrivA] => stat privA in A ) @@ -195,4 +192,3 @@ Array [protC] => protC in X [privC] => privC in X ) - diff --git a/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_001.phpt b/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_001.phpt index 70a3bab9c2..082ef676cd 100644 --- a/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_001.phpt +++ b/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_001.phpt @@ -67,11 +67,11 @@ Array ) Array ( - [privateOverridden] => new value 4 + [privateOverridden] => new value 5 [protectedOverridden] => new value 6 [publicOverridden] => new value 7 ) Set non-existent values from A with no default value: Class A does not have a property named protectedOverridden -Class A does not have a property named privateOverridden \ No newline at end of file +Class A does not have a property named privateOverridden diff --git a/ext/reflection/tests/bug49074.phpt b/ext/reflection/tests/bug49074.phpt index b8990a3db9..0bf94aaabf 100644 --- a/ext/reflection/tests/bug49074.phpt +++ b/ext/reflection/tests/bug49074.phpt @@ -23,13 +23,9 @@ $m['data4'] = 400; var_dump($r->getStaticProperties()); ?> --EXPECT-- -array(4) { +array(2) { [u"data2"]=> int(2) [u"data3"]=> int(3) - [u"data1"]=> - int(1) - [u"data4"]=> - int(4) } -- 2.40.0