Edit report at https://bugs.php.net/bug.php?id=61042&edit=1
ID: 61042
Comment by: vigano dot n at clxeurope dot com
Reported by: vigano dot n at clxeurope dot com
Summary: unserialize issue
Status: Duplicate
Type: Bug
Package: Arrays related
Operating System: Linux Centos
PHP Version: 5.3.10
Block user comment: N
Private report: N
New Comment:
In addition, to be honest I don't believe hat this problem "is that these
strings are not converted to numbers when casting to an array".
The following code, where conversion is not required, doesn't work as well:
$arr = (object)array("value");
$uns = (array)unserialize(serialize($arr));
var_dump($uns);
var_dump(isset($uns["0"]));
result:
array(1) { ["0"]=> string(5) "value" } bool(false)
Previous Comments:
------------------------------------------------------------------------
[2012-02-10 12:14:09] vigano dot n at clxeurope dot com
Anyway the problem affects only unserialized and cast objects.
The following code works properly also with PHP 5.3.9/10:
$arr1 = array("0" => "string");
var_dump(isset($arr1["0"]));
var_dump(isset($arr1[0]));
returning:
bool(true) bool(true)
------------------------------------------------------------------------
[2012-02-10 12:01:19] [email protected]
The bug is not in unserialize; the object is correctly unserialized, with the
rule that objects only have string properties correctly enforced (this was not
enforced before 5.3.9 though: see bug #55798). The problem is that these
strings are not converted to numbers when casting to an array. This is a known
problem and unfortunately the main opinion seems to be this ought not to be
fixed due to performance issues.
------------------------------------------------------------------------
[2012-02-10 11:47:47] vigano dot n at clxeurope dot com
Description:
------------
It seems that, using PHP 5.3.9/10, an unserialized object is not properly cast
to array.
Test script:
---------------
The following code gives different results using PHP 5.3.8 and PHP 5.3.9/10:
$arr = (object)array("value");
$uns = (array)unserialize(serialize($arr));
var_dump($uns);
var_dump(isset($uns[0]));
Expected result:
----------------
Using PHP 5.3.8:
array(1) { [0]=> string(5) "value" } bool(true)
Actual result:
--------------
Using PHP 5.3.9/10:
array(1) { ["0"]=> string(5) "value" } bool(false)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=61042&edit=1