PHP 4.0 Bug #4924: PHP serializes mixed arrays incorrectly
| From: | tobias at phpwizard dot net | 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><wddxPacket
version='1.0'><header/><data><struct><var
name='foo'><array length='2'><boolean
value='true'/><string>stringvalue</string></array></var></struct></data></wddxPacket></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.