php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48171 Unserialize converts string to integer in case of numeric properties
Submitted: 2009-05-06 18:36 UTC Modified: 2009-05-06 18:44 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: csnyder at fcny dot org Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.9 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: csnyder at fcny dot org
New email:
PHP Version: OS:

 

 [2009-05-06 18:36 UTC] csnyder at fcny dot org
Description:
------------
When unserializing a string like O:8:"stdClass":3:{s:5:"22387";s:1:"a";s:5:"22386";s:1:"a";s:5:"22368";s:1:"a";}, the resulting object will have integers as property names instead of strings.

This may be regression of #43614, marked fixed in CVS but that was a year ago.

Reproduce code:
---------------
<?php

// an object with some numeric keys
$keys = array( "1", "2", "3" );
foreach( $keys AS $key ) {
  $obj->{$key} = 'a';
}

var_dump( $obj );
$s = serialize( $obj );
$u = unserialize( $s );
var_dump( $u );

?>

Expected result:
----------------
object(stdClass)#1 (3) {
  ["1"]=>
  string(1) "a"
  ["2"]=>
  string(1) "a"
  ["3"]=>
  string(1) "a"
}
object(stdClass)#2 (3) {
  ["1"]=>
  string(1) "a"
  ["2"]=>
  string(1) "a"
  ["3"]=>
  string(1) "a"
}


Actual result:
--------------
object(stdClass)#1 (3) {
  ["1"]=>
  string(1) "a"
  ["2"]=>
  string(1) "a"
  ["3"]=>
  string(1) "a"
}
object(stdClass)#2 (3) {
  [1]=>
  string(1) "a"
  [2]=>
  string(1) "a"
  [3]=>
  string(1) "a"
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-06 18:39 UTC] jani@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 [2009-05-06 18:43 UTC] csnyder at fcny dot org
Bogus really? If serialize handles numeric property names correctly, why shouldn't unserialize?

Also, would be interested in actual citation in the manual as to why this bug is bogus. Thanks.
 [2009-05-06 18:44 UTC] jani@php.net
See bug #45959
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 16:01:33 2025 UTC