|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28351 Arrays and string keya starting with "\x00" character.
Submitted: 2004-05-10 18:23 UTC Modified: 2004-12-15 04:54 UTC
From: risearch at risearch dot org Assigned:
Status: Not a bug Package: Arrays related
PHP Version: Irrelevant OS: FreeBSD
Private report: No CVE-ID: None
 [2004-05-10 18:23 UTC] risearch at risearch dot org
I use PHP on WinXP and Linux box. Older versions had bug with array keys starting wuth "\x00" character. Now there is no such bug on my computers (WinXP/Apache/php-4.3.4-Win32 & php-4.3.6-Win32 or Linux/Apache 1.3.29/PHP 4.3.4), but some of the script's users complain that script works on Windows box but does not on server. So, I guess that some of the versions still have this bug (like MacOSX/Apache/PHP4.3.2 or BSD/Apache/PHP4.3.4, as reported by users). 

Reproduce code:
$key = "\x00\x00";
$arr[$key] = 1;
$key = "\x00\x44";
$arr[$key] = 2;
$key = "\x44\x44";
$arr[$key] = 3;

$fp = fopen("test","wb");
foreach ($arr as $k => $v) {
fwrite($fp,"'$k' => $v\n");

Expected result:
'\x00\x00' => 1
'\x00D' => 2
'DD' => 3

/* instead of "\x00" zero-character should be written to file */

Actual result:
'' => 1
'' => 2
'DD' => 3


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-05-10 18:29 UTC]
What exactly is the bug?
In the arrays or in the contents of the file?
How are you testing it?
(you need to be more specific if you want someone else to be able to reproduce it)
 [2004-05-10 18:38 UTC] risearch at risearch dot org
The bug is in arrays. When you iterate through whole array some of the keys (which has "\x00" as first character) returned by

foreach ($arr as $k => $v)

are incorrect. Empty string is returned in $k.
 [2004-05-10 18:57 UTC]
On the server where you encounter the problem, run this script and paste the output here:

echo phpversion() . "\n";
foreach(array("\x00D" => 1) as $k => $v) {
    echo bin2hex($k);
echo "done\n";

 [2004-05-10 21:55 UTC] risearch at risearch dot org
The output is


Server info: FreeBSD 4.9-STABLE #0: Thu Jan i386 
I don't know more details because it is not my server.
 [2004-12-15 04:54 UTC]
Thank you for taking the time to report a problem with PHP.
Unfortunately you are not using a current version of PHP -- 
the problem might already be fixed. Please download a new
PHP version from

If you are able to reproduce the bug with one of the latest
versions of PHP, please change the PHP version on this bug report
to the version you tested and change the status back to "Open".
Again, thank you for your continued support of PHP.

And it's not our problem if someone doesn't update..

PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Jan 23 18:01:26 2021 UTC