#28351 [Opn->Fbk]: Arrays and string keya starting with "\x00" character.

From: Date: Mon, 10 May 2004 16:57:45 +0000
Subject: #28351 [Opn->Fbk]: Arrays and string keya starting with "\x00" character.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-59472@lists.php.net to get a copy of this message
ID: 28351 Updated by: wez@php.net Reported By: risearch at risearch dot org -Status: Open +Status: Feedback Bug Type: Arrays related Operating System: FreeBSD PHP Version: Irrelevant New Comment: On the server where you encounter the problem, run this script and paste the output here: <?php echo phpversion() . "\n"; foreach(array("\x00D" => 1) as $k => $v) { echo bin2hex($k); }; echo "done\n"; ?> Previous Comments: ------------------------------------------------------------------------ [2004-05-10 18:38:52] 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:29:57] wez@php.net 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:23:25] risearch at risearch dot org Description: ------------ 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 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=28351&edit=1

« previous php.bugs (#59472) next »