php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45672 changed serialization behaviour
Submitted: 2008-07-31 21:29 UTC Modified: 2008-07-31 23:50 UTC
From: thomas at raptr dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.2.6 OS: FC8
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: thomas at raptr dot com
New email:
PHP Version: OS:

 

 [2008-07-31 21:29 UTC] thomas at raptr dot com
Description:
------------
5.2.6's unserialize() has a different behaviour than 5.2.5's.
In 5.2.6, unserialize() turns integer-based key in a stdClass into
an key of integer type. In 5.2.5, the key left an string type. 

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

class A {

  public function execute() {
    $a = new stdClass();
    $a->{self::B} = "c";
echo "Before:\n";
var_dump($a);

    $str = serialize($a);
    $a = unserialize($str);
echo "After:\n";
var_dump($a);

echo $a->{self::B} . "\n";

  }

  const B = "1";
}

$a = new A();
$a->execute();

?>


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


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

Notice: Undefined property: stdClass::$1 in /tmp/a.php on line 17

Call Stack:
    0.0010      50016   1. {main}() /tmp/a.php:0
    0.0386      50240   2. A->execute() /tmp/a.php:25


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-07-31 23:09 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


 [2008-07-31 23:50 UTC] thomas at raptr dot com
So 5.2.5 is doing the right thing or 5.2.6? I did consult http://us2.php.net/manual/en/function.unserialize.php but it is not specific for this particular bug where php unserializes a string-based index into an integer-based index.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Dec 20 08:00:02 2025 UTC