var_export() does not output an array element with an empty string key.
| Bug #31072 | var_export() does not output an array element with an empty string key. | ||||
|---|---|---|---|---|---|
| Submitted: | 2004-12-13 15:55 UTC | Modified: | 2004-12-17 15:40 UTC | ||
| From: | komura at ma9 dot seikyou dot ne dot jp | Assigned: | helly (profile) | ||
| Status: | Closed | Package: | Variables related | ||
| PHP Version: | 4.3.10RC2 | OS: | Linux | ||
| Private report: | No | CVE-ID: | None | ||
[2004-12-13 15:55 UTC] 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, )
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2004-12-13 16:34 UTC] derick@php.net
[2004-12-17 15:40 UTC] derick@php.net