#31072 [Asn->Csd]: var_export() does not output an array element with an empty string key.
| From: | derick@php.net | Date: | Fri, 17 Dec 2004 14:40:46 +0000 |
| Subject: | #31072 [Asn->Csd]: var_export() does not output an array element with an empty string key. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-70515@lists.php.net to get a copy of this message | ||
ID: 31072
Updated by: derick@php.net
Reported By: komura at ma9 dot seikyou dot ne dot jp
-Status: Assigned
+Status: Closed
Bug Type: Variables related
Operating System: Linux
PHP Version: 4.3.10RC2
Assigned To: helly
New Comment:
This bug has been fixed in CVS.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2004-12-13 16:34:31] derick@php.net
Marcus, you broke this... so fix it :)
------------------------------------------------------------------------
[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