serialize followed by unserialize with numeric object prop. gives integer prop.

Bug #55798 serialize followed by unserialize with numeric object prop. gives integer prop.
Submitted: 2011-09-27 12:51 UTC Modified: 2011-09-28 14:47 UTC
From: lukas dot zierer at abf dot ch Assigned: cataphract (profile)
Status: Closed Package: Unknown/Other Function
PHP Version: Irrelevant OS: at least on Windows
Private report: No CVE-ID: None

 [2011-09-27 12:51 UTC] lukas dot zierer at abf dot ch

Description:
------------
Hi there!

I am having a standard class using numeric keys as properties which works fine in general. The numeric keys are currently Strings. After serializing and unserializing the class, the properties will be converted to Integers which makes them unaccessible. Have a look at the code example below.

Regards
Lukas

Test script:
---------------
<?php

$a = new stdClass();
$a->{0} = 'X';
$a->{1} = 'Y';

var_dump($a);
echo "\n0:", $a->{0}, "\n1:", $a->{1}, "\n\n";

$b = unserialize(serialize($a));

var_dump($b);
echo "\n0:", $b->{0}, "\n1:", $b->{1}, "\n\n";

?>

Expected result:
----------------
object(stdClass)#2 (2) {
  ["0"]=>
  string(1) "X"
  ["1"]=>
  string(1) "Y"
}

Actual result:
--------------
object(stdClass)#2 (2) {
  [0]=>
  string(1) "X"
  [1]=>
  string(1) "Y"
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports

 [2011-09-28 14:13 UTC] cataphract@php.net

-Summary: Type casting problem +Summary: serialize followed by unserialize with numeric object prop. gives integer prop. -Assigned To: +Assigned To: cataphract