From: phpbugs at delinked dot net
Operating system: Linux (Gentoo) and FreeBSD
PHP version: 5.2.6
PHP Bug Type: Scripting Engine problem
Bug description: key in array inaccessible if unserialized as string
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
--
Edit bug report at http://bugs.php.net/?id=44888&edit=1
--
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=44888&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=44888&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=44888&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=44888&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=44888&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=44888&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=44888&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=44888&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=44888&r=support
Expected behavior: http://bugs.php.net/fix.php?id=44888&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=44888&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=44888&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=44888&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=44888&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=44888&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=44888&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=44888&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=44888&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=44888&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=44888&r=mysqlcfg