]> granicus.if.org Git - php/commitdiff
Fixed bug #38132 (ReflectionClass::getStaticProperties() retains \0 in key
authorIlia Alshanetsky <iliaa@php.net>
Tue, 25 Jul 2006 14:06:52 +0000 (14:06 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Tue, 25 Jul 2006 14:06:52 +0000 (14:06 +0000)
names).

NEWS
ext/reflection/php_reflection.c
ext/reflection/tests/bug38132.phpt [new file with mode: 0755]

diff --git a/NEWS b/NEWS
index c0ec779bfe0875356cd4c5f8f2baa873f84a4ef8..7dfe2412e04757e4ff1384a4911745dcbd51c571 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,8 @@ PHP                                                                        NEWS
 
 - Fixed bug #38194 (ReflectionClass::isSubclassOf() returns TRUE for the class
   itself). (Ilia)
+- Fixed bug #38132 (ReflectionClass::getStaticProperties() retains \0 in key
+  names). (Ilia)
 
 24 Jul 2006, PHP 5.2.0RC1
 - Updated bundled MySQL client library to version 5.0.22 in the Windows
index 06c04ab59606f5a71e19e9d59669d35ab6cd697c..c8a6b2ae5eae7e6a389bd04d9d7b9520b63eff25 100644 (file)
@@ -2623,17 +2623,42 @@ ZEND_METHOD(reflection_class, __construct)
    Returns an associative array containing all static property values of the class */
 ZEND_METHOD(reflection_class, getStaticProperties)
 {
-       zval *tmp_copy;
        reflection_object *intern;
        zend_class_entry *ce;
-       
+        HashPosition pos;
+        zval **value;
+
        METHOD_NOTSTATIC_NUMPARAMS(reflection_class_ptr, 0);    
        GET_REFLECTION_OBJECT_PTR(ce);
 
        zend_update_class_constants(ce TSRMLS_CC);
 
        array_init(return_value);
-       zend_hash_copy(Z_ARRVAL_P(return_value), CE_STATIC_MEMBERS(ce), (copy_ctor_func_t) zval_add_ref, (void *) &tmp_copy, sizeof(zval *));
+
+       zend_hash_internal_pointer_reset_ex(CE_STATIC_MEMBERS(ce), &pos);
+
+       while (zend_hash_get_current_data_ex(CE_STATIC_MEMBERS(ce), (void **) &value, &pos) == SUCCESS) {
+               uint key_len;
+               char *key;
+               ulong num_index;
+
+               if (zend_hash_get_current_key_ex(CE_STATIC_MEMBERS(ce), &key, &key_len, &num_index, 0, &pos) != FAILURE && key) {
+                       zval_add_ref(value);
+
+                       if (*key == '\0') {
+                               *key++;
+                               key_len--;
+                               
+                       }
+                       if (*key == '*' && *(key+1) == '\0') {
+                               *(key+1) = *key++;
+                               key_len--;
+                       }
+
+                       zend_hash_update(Z_ARRVAL_P(return_value), key, key_len, value, sizeof(zval *), NULL);
+                }
+               zend_hash_move_forward_ex(CE_STATIC_MEMBERS(ce), &pos);
+       }
 }
 /* }}} */
 
diff --git a/ext/reflection/tests/bug38132.phpt b/ext/reflection/tests/bug38132.phpt
new file mode 100755 (executable)
index 0000000..eaaca85
--- /dev/null
@@ -0,0 +1,33 @@
+--TEST--
+Reflection Bug #38132 (ReflectionClass::getStaticProperties() retains \0 in key names)
+--SKIPIF--
+<?php extension_loaded('reflection') or die('skip'); ?>
+--FILE--
+<?php
+class foo {
+       static protected $bar = 'baz';
+       static public $a = 'a';
+}
+
+$class = new ReflectionClass('foo');
+$properties = $class->getStaticProperties();
+var_dump($properties, array_keys($properties));
+var_dump(isset($properties['*bar'])); // false
+var_dump(isset($properties["\0*\0bar"])); // true
+
+?>
+--EXPECT--
+array(2) {
+  ["*bar"]=>
+  string(3) "baz"
+  ["a"]=>
+  string(1) "a"
+}
+array(2) {
+  [0]=>
+  string(4) "*bar"
+  [1]=>
+  string(1) "a"
+}
+bool(true)
+bool(false)