]> granicus.if.org Git - php/commitdiff
implement (or fix?) #41884 (ReflectionClass::getDefaultProperties() does not handle...
authorAntony Dovgal <tony2001@php.net>
Wed, 11 Jul 2007 22:03:59 +0000 (22:03 +0000)
committerAntony Dovgal <tony2001@php.net>
Wed, 11 Jul 2007 22:03:59 +0000 (22:03 +0000)
ext/reflection/php_reflection.c
ext/reflection/tests/bug41884.phpt [new file with mode: 0644]

index b1faaad55af3f103af4fc74cdb3d3524ea92b347..0cd558ecdfb438531dae52c9ac0e1ca03407190c 100644 (file)
@@ -2852,7 +2852,8 @@ ZEND_METHOD(reflection_class, getDefaultProperties)
 {
        reflection_object *intern;
        zend_class_entry *ce;
-       int count;
+       int count, i;
+       HashTable *ht_list[3];
        
        METHOD_NOTSTATIC_NUMPARAMS(reflection_class_ptr, 0);    
        GET_REFLECTION_OBJECT_PTR(ce);
@@ -2860,34 +2861,40 @@ ZEND_METHOD(reflection_class, getDefaultProperties)
 
        zend_update_class_constants(ce TSRMLS_CC);
 
-       count = zend_hash_num_elements(&ce->default_properties);
-       if (count > 0) {
-               HashPosition pos;
-               zval **prop;
-
-               zend_hash_internal_pointer_reset_ex(&ce->default_properties, &pos);
-               while (zend_hash_get_current_data_ex(&ce->default_properties, (void **) &prop, &pos) == SUCCESS) {
-                       zstr key, class_name, prop_name;
-                       uint key_len;
-                       ulong num_index;
-                       zval *prop_copy;
+       ht_list[0] = CE_STATIC_MEMBERS(ce);
+       ht_list[1] = &ce->default_properties;
+       ht_list[2] = NULL; /* this should be always the last element */
 
-                       zend_hash_get_current_key_ex(&ce->default_properties, &key, &key_len, &num_index, 0, &pos);
-                       zend_hash_move_forward_ex(&ce->default_properties, &pos);
-                       zend_u_unmangle_property_name(UG(unicode)?IS_UNICODE:IS_STRING, key, key_len-1, &class_name, &prop_name);
-                       if (class_name.s && class_name.s[0] != '*' && 
-                               (UG(unicode)?u_strcmp(class_name.u, ce->name.u):strcmp(class_name.s, ce->name.s))) {
-                               /* filter privates from base classes */
-                               continue;
-                       }
+       for (i = 0; ht_list[i] != NULL; i++) {
+               count = zend_hash_num_elements(ht_list[i]);
+               if (count > 0) {
+                       HashPosition pos;
+                       zval **prop;
+
+                       zend_hash_internal_pointer_reset_ex(ht_list[i], &pos);
+                       while (zend_hash_get_current_data_ex(ht_list[i], (void **) &prop, &pos) == SUCCESS) {
+                               zstr key, class_name, prop_name;
+                               uint key_len;
+                               ulong num_index;
+                               zval *prop_copy;
+
+                               zend_hash_get_current_key_ex(ht_list[i], &key, &key_len, &num_index, 0, &pos);
+                               zend_hash_move_forward_ex(ht_list[i], &pos);
+                               zend_u_unmangle_property_name(UG(unicode)?IS_UNICODE:IS_STRING, key, key_len-1, &class_name, &prop_name);
+                               if (class_name.s && class_name.s[0] != '*' && 
+                                       (UG(unicode)?u_strcmp(class_name.u, ce->name.u):strcmp(class_name.s, ce->name.s))) {
+                                       /* filter privates from base classes */
+                                       continue;
+                               }
 
-                       /* copy: enforce read only access */
-                       ALLOC_ZVAL(prop_copy);
-                       *prop_copy = **prop;
-                       zval_copy_ctor(prop_copy);
-                       INIT_PZVAL(prop_copy);
+                               /* copy: enforce read only access */
+                               ALLOC_ZVAL(prop_copy);
+                               *prop_copy = **prop;
+                               zval_copy_ctor(prop_copy);
+                               INIT_PZVAL(prop_copy);
 
-                       add_u_assoc_zval(return_value, ZEND_STR_TYPE, prop_name, prop_copy);
+                               add_u_assoc_zval(return_value, ZEND_STR_TYPE, prop_name, prop_copy);
+                       }
                }
        }
 }
diff --git a/ext/reflection/tests/bug41884.phpt b/ext/reflection/tests/bug41884.phpt
new file mode 100644 (file)
index 0000000..dfecf84
--- /dev/null
@@ -0,0 +1,33 @@
+--TEST--
+Bug #41884 (ReflectionClass::getDefaultProperties() does not handle static attributes)
+--FILE--
+<?php
+
+class Foo
+{
+       protected static $fooStatic = 'foo';
+       protected $foo = 'foo';
+}
+
+$class = new ReflectionClass('Foo');
+
+var_dump($class->getDefaultProperties());
+
+echo "Done\n";
+?>
+--EXPECTF--    
+array(2) {
+  ["fooStatic"]=>
+  string(3) "foo"
+  ["foo"]=>
+  string(3) "foo"
+}
+Done
+--UEXPECTF--
+array(2) {
+  [u"fooStatic"]=>
+  unicode(3) "foo"
+  [u"foo"]=>
+  unicode(3) "foo"
+}
+Done