php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
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
 [2011-09-28 14:47 UTC] cataphract@php.net
Automatic comment from SVN on behalf of cataphract
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=317438
Log: - Fixed #55798: serialize followed by unserialize with numeric object prop.
  gives integer prop.
 [2011-09-28 14:47 UTC] cataphract@php.net
-Status: Assigned +Status: Closed
 [2011-09-28 14:47 UTC] cataphract@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 [2012-04-18 09:48 UTC] laruence@php.net
Automatic comment on behalf of cataphract
Revision: http://git.php.net/?p=php-src.git;a=commit;h=4eb080226b0807be8720e69f2c2eb2256bdf03bb
Log: - Fixed #55798: serialize followed by unserialize with numeric object prop.   gives integer prop.
 [2012-07-24 23:39 UTC] rasmus@php.net
Automatic comment on behalf of cataphract
Revision: http://git.php.net/?p=php-src.git;a=commit;h=4eb080226b0807be8720e69f2c2eb2256bdf03bb
Log: - Fixed #55798: serialize followed by unserialize with numeric object prop.   gives integer prop.
 [2013-11-17 09:36 UTC] laruence@php.net
Automatic comment on behalf of cataphract
Revision: http://git.php.net/?p=php-src.git;a=commit;h=4eb080226b0807be8720e69f2c2eb2256bdf03bb
Log: - Fixed #55798: serialize followed by unserialize with numeric object prop.   gives integer prop.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 08:01:29 2024 UTC