#31072 [Opn->Asn]: var_export() does not output an array element with an empty string key.
ID: 31072
Updated by: derick@php.net
Reported By: komura at ma9 dot seikyou dot ne dot jp
-Status: Open
+Status: Assigned
Bug Type: Variables related
Operating System: Linux
PHP Version: 4.3.10RC2
-Assigned To:
+Assigned To: helly
New Comment:
Marcus, you broke this... so fix it :)
Previous Comments:
------------------------------------------------------------------------
[2004-12-13 15:55:30] komura at ma9 dot seikyou dot ne dot jp
Description:
------------
var_export() in PHP 4.3.10RC1/RC2 does not output an array element with
an empty string key.
It appears that the following patch is the cause of this problem.
http://cvs.php.net/diff.php/php-src/ext/standard/var.c?r1=1.150.2.14&r2=1.150.2.15&ty=u
@@ -260,13 +267,17 @@ static int php_array_element_export(zval
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'", level + 1, ' ');
- PHPWRITE(key, key_len);
- php_printf("' => ");
- efree(key);
+ 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);
+ }
}
Reproduce code:
---------------
var_export( array( '' => 1, 'a' => 2 ) );
Expected result:
----------------
array (
'' => 1,
'a' => 2,
)
Actual result:
--------------
array (
'a' => 2,
)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=31072&edit=1
Thread (3 messages)