felipe                                   Sat, 01 Aug 2009 20:44:00 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=286635

Log:
- Fixed ReflectionClass::getStaticProperties() to do not return the private 
properties from parent class;
  behavior already adopted in ReflectionClass::getDefaultProperties() and 
ReflectionClass::getProperties().

Changed paths:
    U   php/php-src/branches/PHP_5_2/ext/reflection/php_reflection.c
    U   
php/php-src/branches/PHP_5_2/ext/reflection/tests/ReflectionClass_getDefaultProperties_001.phpt
    U   
php/php-src/branches/PHP_5_2/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_001.phpt
    U   php/php-src/branches/PHP_5_2/ext/reflection/tests/bug49074.phpt
    U   php/php-src/branches/PHP_5_3/ext/reflection/php_reflection.c
    U   
php/php-src/branches/PHP_5_3/ext/reflection/tests/ReflectionClass_getDefaultProperties_001.phpt
    U   
php/php-src/branches/PHP_5_3/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_001.phpt
    U   php/php-src/branches/PHP_5_3/ext/reflection/tests/bug49074.phpt
    U   php/php-src/trunk/ext/reflection/php_reflection.c
    U   
php/php-src/trunk/ext/reflection/tests/ReflectionClass_getDefaultProperties_001.phpt
    U   
php/php-src/trunk/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_001.phpt
    U   php/php-src/trunk/ext/reflection/tests/bug49074.phpt

Modified: php/php-src/branches/PHP_5_2/ext/reflection/php_reflection.c
===================================================================
--- php/php-src/branches/PHP_5_2/ext/reflection/php_reflection.c	2009-08-01 20:08:21 UTC (rev 286634)
+++ php/php-src/branches/PHP_5_2/ext/reflection/php_reflection.c	2009-08-01 20:44:00 UTC (rev 286635)
@@ -2729,13 +2729,16 @@

 			zend_unmangle_property_name(key, key_len-1, &class_name, &prop_name);

-			/* 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 && class_name[0] != '*' && strcmp(class_name, ce->name))) {
+				/* copy: enforce read only access */
+				ALLOC_ZVAL(prop_copy);
+				*prop_copy = **value;
+				zval_copy_ctor(prop_copy);
+				INIT_PZVAL(prop_copy);

-			add_assoc_zval(return_value, prop_name, prop_copy);
+				add_assoc_zval(return_value, prop_name, prop_copy);
+			}
 		}
 		zend_hash_move_forward_ex(CE_STATIC_MEMBERS(ce), &pos);
 	}

Modified: php/php-src/branches/PHP_5_2/ext/reflection/tests/ReflectionClass_getDefaultProperties_001.phpt
===================================================================
--- php/php-src/branches/PHP_5_2/ext/reflection/tests/ReflectionClass_getDefaultProperties_001.phpt	2009-08-01 20:08:21 UTC (rev 286634)
+++ php/php-src/branches/PHP_5_2/ext/reflection/tests/ReflectionClass_getDefaultProperties_001.phpt	2009-08-01 20:44:00 UTC (rev 286635)
@@ -109,13 +109,12 @@
 (
     [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 @@
 (
     [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 @@
     [protC] => protC in X
     [privC] => privC in X
 )
-

Modified: php/php-src/branches/PHP_5_2/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_001.phpt
===================================================================
--- php/php-src/branches/PHP_5_2/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_001.phpt	2009-08-01 20:08:21 UTC (rev 286634)
+++ php/php-src/branches/PHP_5_2/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_001.phpt	2009-08-01 20:44:00 UTC (rev 286635)
@@ -67,11 +67,11 @@
 )
 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

Modified: php/php-src/branches/PHP_5_2/ext/reflection/tests/bug49074.phpt
===================================================================
--- php/php-src/branches/PHP_5_2/ext/reflection/tests/bug49074.phpt	2009-08-01 20:08:21 UTC (rev 286634)
+++ php/php-src/branches/PHP_5_2/ext/reflection/tests/bug49074.phpt	2009-08-01 20:44:00 UTC (rev 286635)
@@ -23,13 +23,9 @@
 var_dump($r->getStaticProperties());
 ?>
 --EXPECT--
-array(4) {
+array(2) {
   ["data2"]=>
   int(2)
   ["data3"]=>
   int(3)
-  ["data1"]=>
-  int(1)
-  ["data4"]=>
-  int(4)
 }

Modified: php/php-src/branches/PHP_5_3/ext/reflection/php_reflection.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/reflection/php_reflection.c	2009-08-01 20:08:21 UTC (rev 286634)
+++ php/php-src/branches/PHP_5_3/ext/reflection/php_reflection.c	2009-08-01 20:44:00 UTC (rev 286635)
@@ -3060,13 +3060,16 @@

 			zend_unmangle_property_name(key, key_len-1, &class_name, &prop_name);

-			/* 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 && class_name[0] != '*' && strcmp(class_name, ce->name))) {
+				/* copy: enforce read only access */
+				ALLOC_ZVAL(prop_copy);
+				*prop_copy = **value;
+				zval_copy_ctor(prop_copy);
+				INIT_PZVAL(prop_copy);

-			add_assoc_zval(return_value, prop_name, prop_copy);
+				add_assoc_zval(return_value, prop_name, prop_copy);
+			}
 		}
 		zend_hash_move_forward_ex(CE_STATIC_MEMBERS(ce), &pos);
 	}

Modified: php/php-src/branches/PHP_5_3/ext/reflection/tests/ReflectionClass_getDefaultProperties_001.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/reflection/tests/ReflectionClass_getDefaultProperties_001.phpt	2009-08-01 20:08:21 UTC (rev 286634)
+++ php/php-src/branches/PHP_5_3/ext/reflection/tests/ReflectionClass_getDefaultProperties_001.phpt	2009-08-01 20:44:00 UTC (rev 286635)
@@ -109,13 +109,12 @@
 (
     [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 @@
 (
     [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 @@
     [protC] => protC in X
     [privC] => privC in X
 )
-

Modified: php/php-src/branches/PHP_5_3/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_001.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_001.phpt	2009-08-01 20:08:21 UTC (rev 286634)
+++ php/php-src/branches/PHP_5_3/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_001.phpt	2009-08-01 20:44:00 UTC (rev 286635)
@@ -67,11 +67,11 @@
 )
 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

Modified: php/php-src/branches/PHP_5_3/ext/reflection/tests/bug49074.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/reflection/tests/bug49074.phpt	2009-08-01 20:08:21 UTC (rev 286634)
+++ php/php-src/branches/PHP_5_3/ext/reflection/tests/bug49074.phpt	2009-08-01 20:44:00 UTC (rev 286635)
@@ -23,13 +23,9 @@
 var_dump($r->getStaticProperties());
 ?>
 --EXPECT--
-array(4) {
+array(2) {
   ["data2"]=>
   int(2)
   ["data3"]=>
   int(3)
-  ["data1"]=>
-  int(1)
-  ["data4"]=>
-  int(4)
 }

Modified: php/php-src/trunk/ext/reflection/php_reflection.c
===================================================================
--- php/php-src/trunk/ext/reflection/php_reflection.c	2009-08-01 20:08:21 UTC (rev 286634)
+++ php/php-src/trunk/ext/reflection/php_reflection.c	2009-08-01 20:44:00 UTC (rev 286635)
@@ -3216,13 +3216,16 @@
 			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);
 	}

Modified: php/php-src/trunk/ext/reflection/tests/ReflectionClass_getDefaultProperties_001.phpt
===================================================================
--- php/php-src/trunk/ext/reflection/tests/ReflectionClass_getDefaultProperties_001.phpt	2009-08-01 20:08:21 UTC (rev 286634)
+++ php/php-src/trunk/ext/reflection/tests/ReflectionClass_getDefaultProperties_001.phpt	2009-08-01 20:44:00 UTC (rev 286635)
@@ -109,13 +109,12 @@
 (
     [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 @@
 (
     [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 @@
     [protC] => protC in X
     [privC] => privC in X
 )
-

Modified: php/php-src/trunk/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_001.phpt
===================================================================
--- php/php-src/trunk/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_001.phpt	2009-08-01 20:08:21 UTC (rev 286634)
+++ php/php-src/trunk/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_001.phpt	2009-08-01 20:44:00 UTC (rev 286635)
@@ -67,11 +67,11 @@
 )
 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

Modified: php/php-src/trunk/ext/reflection/tests/bug49074.phpt
===================================================================
--- php/php-src/trunk/ext/reflection/tests/bug49074.phpt	2009-08-01 20:08:21 UTC (rev 286634)
+++ php/php-src/trunk/ext/reflection/tests/bug49074.phpt	2009-08-01 20:44:00 UTC (rev 286635)
@@ -23,13 +23,9 @@
 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)
 }
-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to