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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: tobias at phpwizard dot net
New email:
PHP Version: OS:

 

 [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: Tue Oct 08 21:01:27 2024 UTC