php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #4924 PHP serializes mixed arrays incorrectly
Submitted: 2000-06-09 08:50 UTC Modified: 2000-06-09 15:52 UTC
From: tobias at phpwizard dot net Assigned:
Status: Closed Package: WDDX related
PHP Version: 4.0 Latest CVS (09/06/2000) OS: Suse Linux 6.1
Private report: No CVE-ID: None
 [2000-06-09 08:50 UTC] tobias at phpwizard dot net
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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-06-09 15:52 UTC] andrei at cvs dot php dot net
Fixed in CVS.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Dec 11 17:01:28 2024 UTC