php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44888 key in array inaccessible if unserialized as string
Submitted: 2008-05-02 04:00 UTC Modified: 2008-05-02 04:45 UTC
Votes:2
Avg. Score:4.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: phpbugs at delinked dot net Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.5 OS: Linux (Gentoo) and FreeBSD
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: phpbugs at delinked dot net
New email:
PHP Version: OS:

 

 [2008-05-02 04:00 UTC] phpbugs at delinked dot net
Description:
------------
If an array is unserialized where a numerical key is represented as a string (s:3:"123"), the key and its value become inaccessible via direct access ($array[123]) as well as via isset, is_*, array_key_exists, var_dump, etc. The key and value are accessible via var_dump of the whole array, or via foreach.

Reproduce code:
---------------
<?php
$bob = unserialize('a:1:{s:5:"words";a:1:{s:3:"123";s:3:"foo";}}');
echo var_dump($bob);
echo var_dump($bob['words']['123']);
$id1 = '123';
echo var_dump($bob['words'][$id1]);
$id2 = 123;
echo var_dump($bob['words'][$id2]);
echo 0+isset($bob['words']['123']),0+isset($bob['words'][$id1]),0+isset($bob['words'][$id2]);
echo 0+array_key_exists('123',$bob['words']),0+array_key_exists($id1,$bob['words']),0+array_key_exists($id2,$bob['words']);
?>

Expected result:
----------------
array(1) {
  ["words"]=>
  array(1) {
    [123]=>
    string(3) "foo"
  }
}
string(3) "foo"
string(3) "foo"
string(3) "foo"
111111

- OR -

array(1) {
  ["words"]=>
  array(1) {
    ["123"]=>
    string(3) "foo"
  }
}
string(3) "foo"
string(3) "foo"
string(3) "foo"
111111

Actual result:
--------------
array(1) {
  ["words"]=>
  array(1) {
    ["123"]=>
    string(3) "foo"
  }
}
NULL
NULL
NULL
000000

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-05-02 04:20 UTC] dbushea at gmail dot com
Unable to reproduce on:
Windows XP 32/64bit
Windows 2003 Web/Standard/Enterprise
Windows 2000 Server

Results are exactly the same from each OS:
array(1) {
  ["words"]=>
  array(1) {
    [123]=>
    string(3) "foo"
  }
}
string(3) "foo"
string(3) "foo"
string(3) "foo"
111111
 [2008-05-02 04:28 UTC] phpbugs at delinked dot net
To add to dbushea's comment, I've been able to produce this using the Gentoo portage version (5.2.5p1), FreeBSD port version (5.2.5 w/Suhosin), and 5.2.5 manually compiled on Gentoo and Fedora.
 [2008-05-02 04:45 UTC] phpbugs at delinked dot net
Fixed in 5.2.6.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 15 16:01:33 2025 UTC