]> granicus.if.org Git - php/commitdiff
Fixed bug #26458 (var_dump(), var_export(), debug_zval_dump() not binary
authorIlia Alshanetsky <iliaa@php.net>
Sat, 29 Nov 2003 04:43:06 +0000 (04:43 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Sat, 29 Nov 2003 04:43:06 +0000 (04:43 +0000)
safe for array keys).

ext/standard/tests/array/007.phpt
ext/standard/tests/array/array_intersect_1.phpt
ext/standard/tests/array/bug26458.phpt [new file with mode: 0644]
ext/standard/var.c

index 753aced821a9cd11d1a00e2846e7bdffa9ec9593..6f2fd98e30f59b9717470e3909a28aa727124947 100644 (file)
@@ -309,23 +309,17 @@ $b=array (
 var_dump(array_udiff_uassoc($a, $b, "comp_func_cr", "comp_func"));
 array(3) {
   ["0.1"]=>
-  object(cr)#%d (%d) {
-    [""]=>
-    int(9)
+  object(cr)#1 (2) {
     ["public_member"]=>
     int(9)
   }
   ["0.5"]=>
-  object(cr)#%d (%d) {
-    [""]=>
-    int(12)
+  object(cr)#2 (2) {
     ["public_member"]=>
     int(12)
   }
   [0]=>
-  object(cr)#%d (%d) {
-    [""]=>
-    int(23)
+  object(cr)#3 (2) {
     ["public_member"]=>
     int(23)
   }
@@ -387,23 +381,17 @@ $b=array (
 var_dump(array_udiff_uassoc($a, $b, array("cr", "comp_func_cr"), "comp_func"));
 array(3) {
   ["0.1"]=>
-  object(cr)#%d (%d) {
-    [""]=>
-    int(9)
+  object(cr)#1 (2) {
     ["public_member"]=>
     int(9)
   }
   ["0.5"]=>
-  object(cr)#%d (%d) {
-    [""]=>
-    int(12)
+  object(cr)#2 (2) {
     ["public_member"]=>
     int(12)
   }
   [0]=>
-  object(cr)#%d (%d) {
-    [""]=>
-    int(23)
+  object(cr)#3 (2) {
     ["public_member"]=>
     int(23)
   }
@@ -465,37 +453,27 @@ $b=array (
 var_dump(array_diff_assoc($a, $b));
 array(5) {
   ["0.1"]=>
-  object(cr)#%d (%d) {
-    [""]=>
-    int(9)
+  object(cr)#1 (2) {
     ["public_member"]=>
     int(9)
   }
   ["0.5"]=>
-  object(cr)#%d (%d) {
-    [""]=>
-    int(12)
+  object(cr)#2 (2) {
     ["public_member"]=>
     int(12)
   }
   [0]=>
-  object(cr)#%d (%d) {
-    [""]=>
-    int(23)
+  object(cr)#3 (2) {
     ["public_member"]=>
     int(23)
   }
   [1]=>
-  object(cr)#%d (%d) {
-    [""]=>
-    int(4)
+  object(cr)#4 (2) {
     ["public_member"]=>
     int(4)
   }
   [2]=>
-  object(cr)#%d (%d) {
-    [""]=>
-    int(-15)
+  object(cr)#5 (2) {
     ["public_member"]=>
     int(-15)
   }
@@ -557,16 +535,12 @@ $b=array (
 var_dump(array_udiff($a, $b, "comp_func_cr"));
 array(2) {
   ["0.5"]=>
-  object(cr)#%d (%d) {
-    [""]=>
-    int(12)
+  object(cr)#2 (2) {
     ["public_member"]=>
     int(12)
   }
   [0]=>
-  object(cr)#%d (%d) {
-    [""]=>
-    int(23)
+  object(cr)#3 (2) {
     ["public_member"]=>
     int(23)
   }
@@ -628,23 +602,17 @@ $b=array (
 var_dump(array_udiff_assoc($a, $b, "comp_func_cr"));
 array(3) {
   ["0.1"]=>
-  object(cr)#%d (%d) {
-    [""]=>
-    int(9)
+  object(cr)#1 (2) {
     ["public_member"]=>
     int(9)
   }
   ["0.5"]=>
-  object(cr)#%d (%d) {
-    [""]=>
-    int(12)
+  object(cr)#2 (2) {
     ["public_member"]=>
     int(12)
   }
   [0]=>
-  object(cr)#%d (%d) {
-    [""]=>
-    int(23)
+  object(cr)#3 (2) {
     ["public_member"]=>
     int(23)
   }
index 5a09d84d71accd9316ed870ad14cc929c7b022f3..34b94833b0b2641d0463fdb917d6f960bbe817ef 100644 (file)
@@ -204,23 +204,17 @@ $b=array (
 var_dump(array_uintersect($a, $b, "comp_func_cr"));
 array(3) {
   ["0.1"]=>
-  object(cr)#%d (2) {
-    [""]=>
-    int(9)
+  object(cr)#1 (2) {
     ["public_member"]=>
     int(9)
   }
   [1]=>
-  object(cr)#%d (2) {
-    [""]=>
-    int(4)
+  object(cr)#4 (2) {
     ["public_member"]=>
     int(4)
   }
   [2]=>
-  object(cr)#%d (2) {
-    [""]=>
-    int(-15)
+  object(cr)#5 (2) {
     ["public_member"]=>
     int(-15)
   }
@@ -343,16 +337,12 @@ $b=array (
 var_dump(array_uintersect_assoc($a, $b, "comp_func_cr"));
 array(2) {
   [1]=>
-  object(cr)#%d (2) {
-    [""]=>
-    int(4)
+  object(cr)#4 (2) {
     ["public_member"]=>
     int(4)
   }
   [2]=>
-  object(cr)#%d (2) {
-    [""]=>
-    int(-15)
+  object(cr)#5 (2) {
     ["public_member"]=>
     int(-15)
   }
@@ -475,16 +465,12 @@ $b=array (
 var_dump(array_uintersect_uassoc($a, $b, "comp_func_cr", "comp_func"));
 array(2) {
   [1]=>
-  object(cr)#%d (2) {
-    [""]=>
-    int(4)
+  object(cr)#4 (2) {
     ["public_member"]=>
     int(4)
   }
   [2]=>
-  object(cr)#%d (2) {
-    [""]=>
-    int(-15)
+  object(cr)#5 (2) {
     ["public_member"]=>
     int(-15)
   }
@@ -548,16 +534,12 @@ $b=array (
 var_dump(array_uintersect_uassoc($a, $b, array("cr", "comp_func_cr"), "comp_func"));
 array(2) {
   [1]=>
-  object(cr)#%d (2) {
-    [""]=>
-    int(4)
+  object(cr)#4 (2) {
     ["public_member"]=>
     int(4)
   }
   [2]=>
-  object(cr)#%d (2) {
-    [""]=>
-    int(-15)
+  object(cr)#5 (2) {
     ["public_member"]=>
     int(-15)
   }
diff --git a/ext/standard/tests/array/bug26458.phpt b/ext/standard/tests/array/bug26458.phpt
new file mode 100644 (file)
index 0000000..d24e1f1
Binary files /dev/null and b/ext/standard/tests/array/bug26458.phpt differ
index a33c8da200cc06db11d78b0d37b9ae02b3e8e9a5..0358080cac01a70747a3cbc0e8d611529c896b98 100644 (file)
@@ -50,7 +50,15 @@ static int php_array_element_dump(zval **zv, int num_args, va_list args, zend_ha
        if (hash_key->nKeyLength==0) { /* numeric key */
                php_printf("%*c[%ld]=>\n", level + 1, ' ', hash_key->h);
        } else { /* string key */
-               php_printf("%*c[\"%s\"]=>\n", level + 1, ' ', hash_key->arKey);
+               if (va_arg(args, int) && hash_key->arKey[0] == '\0') { 
+                       /* XXX: perphaps when we are inside the class we should permit access to 
+                        * private & protected values
+                        */
+                       return 0;
+               }
+               php_printf("%*c[\"", level + 1, ' ');
+               PHPWRITE(hash_key->arKey, hash_key->nKeyLength - 1);
+               php_printf("\"]=>\n");
        }
        php_var_dump(zv, level + 2 TSRMLS_CC);
        return 0;
@@ -107,7 +115,7 @@ PHPAPI void php_var_dump(zval **struc, int level TSRMLS_DC)
                efree(class_name);
 head_done:
                if (myht) {
-                       zend_hash_apply_with_arguments(myht, (apply_func_args_t) php_array_element_dump, 1, level);
+                       zend_hash_apply_with_arguments(myht, (apply_func_args_t) php_array_element_dump, 1, level, (Z_TYPE_PP(struc) == IS_ARRAY ? 0 : 1));
                }
                if (level > 1) {
                        php_printf("%*c", level-1, ' ');
@@ -166,7 +174,15 @@ static int zval_array_element_dump(zval **zv, int num_args, va_list args, zend_h
        if (hash_key->nKeyLength==0) { /* numeric key */
                php_printf("%*c[%ld]=>\n", level + 1, ' ', hash_key->h);
        } else { /* string key */
-               php_printf("%*c[\"%s\"]=>\n", level + 1, ' ', hash_key->arKey);
+               /* XXX: perphaps when we are inside the class we should permit access to 
+                * private & protected values
+                */
+               if (va_arg(args, int) && hash_key->arKey[0] == '\0') {
+                       return 0;
+               }
+               php_printf("%*c[\"", level + 1, ' ');
+               PHPWRITE(hash_key->arKey, hash_key->nKeyLength - 1);
+               php_printf("\"]=>\n");
        }
        php_debug_zval_dump(zv, level + 2 TSRMLS_CC);
        return 0;
@@ -213,7 +229,7 @@ PHPAPI void php_debug_zval_dump(zval **struc, int level TSRMLS_DC)
                efree(class_name);
 head_done:
                if (myht) {
-                       zend_hash_apply_with_arguments(myht, (apply_func_args_t) zval_array_element_dump, 1, level);
+                       zend_hash_apply_with_arguments(myht, (apply_func_args_t) zval_array_element_dump, 1, level, (Z_TYPE_PP(struc) == IS_ARRAY ? 0 : 1));
                }
                if (level > 1) {
                        php_printf("%*c", level-1, ' ');
@@ -271,11 +287,20 @@ static int php_array_element_export(zval **zv, int num_args, va_list args, zend_
        if (hash_key->nKeyLength==0) { /* numeric key */
                php_printf("%*c%ld => ", level + 1, ' ', hash_key->h);
        } else { /* string key */
-               char *key;
-               int key_len;
-               key = php_addcslashes(hash_key->arKey, hash_key->nKeyLength - 1, &key_len, 0, "'\\", 2 TSRMLS_CC);
-               php_printf("%*c'%s' => ", level + 1, ' ', key);
-               efree(key);
+               /* XXX: perphaps when we are inside the class we should permit access to 
+                * private & protected values
+                */
+               if (va_arg(args, int) && hash_key->arKey[0] == '\0') {
+                       return 0;
+               } else {
+                       char *key;
+                       int key_len;
+                       key = php_addcslashes(hash_key->arKey, hash_key->nKeyLength - 1, &key_len, 0, "'\\", 2 TSRMLS_CC);
+                       php_printf("%*c'", level + 1, ' ');
+                       PHPWRITE(key, key_len);
+                       php_printf("' => ");
+                       efree(key);
+               }
        }
        php_var_export(zv, level + 2 TSRMLS_CC);
        PUTS (",\n");
@@ -331,7 +356,7 @@ PHPAPI void php_var_export(zval **struc, int level TSRMLS_DC)
                        php_printf("\n%*c", level - 1, ' ');
                }
                PUTS ("array (\n");
-               zend_hash_apply_with_arguments(myht, (apply_func_args_t) php_array_element_export, 1, level);
+               zend_hash_apply_with_arguments(myht, (apply_func_args_t) php_array_element_export, 1, level, (Z_TYPE_PP(struc) == IS_ARRAY ? 0 : 1));
                if (level > 1) {
                        php_printf("%*c", level - 1, ' ');
                }