From:             komura at ma9 dot seikyou dot ne dot jp
Operating system: Linux
PHP version:      4.3.10RC2
PHP Bug Type:     Variables related
Bug description:  var_export() does not output an array element with an empty 
string key.

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 bug report at http://bugs.php.net/?id=31072&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=31072&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=31072&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=31072&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=31072&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=31072&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=31072&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=31072&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=31072&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=31072&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=31072&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=31072&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=31072&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=31072&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=31072&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=31072&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=31072&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=31072&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=31072&r=float
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=31072&r=mysqlcfg

Reply via email to