PHP 4.0 Bug #4924: PHP serializes mixed arrays incorrectly

From: Date: Fri, 09 Jun 2000 06:50:06 +0000
Subject: PHP 4.0 Bug #4924: PHP serializes mixed arrays incorrectly
Groups: php.dev 
Request: Send a blank email to php-dev+get-20677@lists.php.net to get a copy of this message
From: tobias@phpwizard.net Operating system: Suse Linux 6.1 PHP version: 4.0 Latest CVS (09/06/2000) PHP Bug Type: WDDX related Bug description: PHP serializes mixed arrays incorrectly If the first element of an array has a numeric index, PHP treats the whole array as numerically indexed array, even if the subsequent elements of the array have a string key. session_start(); printf('Current session data is: <pre>%s</pre>', htmlspecialchars(session_encode())); var_dump($foo); $foo = array (0 => true, "foo" => "stringvalue"); session_register("foo"); print('<p>'); var_dump($foo); This code leads to: Current session data is: <pre>&lt;wddxPacket version='1.0'&gt;&lt;header/&gt;&lt;data&gt;&lt;struct&gt;&lt;var name='foo'&gt;&lt;array length='2'&gt;&lt;boolean value='true'/&gt;&lt;string&gt;stringvalue&lt;/string&gt;&lt;/array&gt;&lt;/var&gt;&lt;/struct&gt;&lt;/data&gt;&lt;/wddxPacket&gt;</pre>array(2) { [0]=> bool(true) [1]=> string(11) "stringvalue" } <p>array(2) { [0]=> bool(true) ["foo"]=> string(11) "stringvalue" } A possible solution would be to include always the index when serializing an array, be it numeric or string.

« previous php.dev (#20677) next »