|  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 Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
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. 

printf('Current session data is: <pre>%s</pre>', htmlspecialchars(session_encode()));
$foo = array (0 => true, "foo" => "stringvalue");

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) {
  string(11) "stringvalue"
<p>array(2) {
  string(11) "stringvalue"

A possible solution would be to include always the index when serializing an array, be it numeric or string.


Add a Patch

Pull Requests

Add a Pull Request


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: Thu May 30 03:01:30 2024 UTC