From:             cameron dot junge at sella dot co dot nz
Operating system: Ubuntu 12.10
PHP version:      5.4.11
Package:          Scripting Engine problem
Bug Type:         Bug
Bug description:Serialized object becomes r:2, which breaks unserialization

Description:
------------
When trying to serialize an inherited object, PHP 5.4 serializes the
inherited object as a reference to the parent object, when there is no
parent object to reference.

This works fine in PHP 5.3.

See test script for an example.

Test script:
---------------
class A implements \Serializable {

    public function serialize()
    {
        $s = new \stdClass();
        $s->id = 1;
        var_dump($s);
        return serialize($s);
    }
    public function unserialize($s)
    {
    }

}
class B extends A {

    public function serialize()
    {
        $p = parent::serialize();
        $s = unserialize($p);
        $s->foo = 'bar';
        $s2 = serialize($s);
        var_dump($p, $s, $s2); // $s2 = 'r:2'
        //var_dump(unserialize($s2)); // will throw error as can't
unserialize
        die;
        //return serialize($s);
    }
}

$b = new B;
serialize($b);

Expected result:
----------------
// PHP5.3.6

object(stdClass)[794]
  public 'id' => int 1

string 'O:8:"stdClass":1:{s:2:"id";i:1;}' (length=32)

object(stdClass)[794]
  public 'id' => int 1
  public 'foo' => string 'bar' (length=3)

string 'O:8:"stdClass":2:{s:2:"id";i:1;s:3:"foo";s:3:"bar";}' (length=52)



Actual result:
--------------
// PHP 5.4.11
object(stdClass)[794]
  public 'id' => int 1

string 'O:8:"stdClass":1:{s:2:"id";i:1;}' (length=32)

object(stdClass)[794]
  public 'id' => int 1
  public 'foo' => string 'bar' (length=3)

string 'r:2;' (length=4)


-- 
Edit bug report at https://bugs.php.net/bug.php?id=64206&edit=1
-- 
Try a snapshot (PHP 5.4):   
https://bugs.php.net/fix.php?id=64206&r=trysnapshot54
Try a snapshot (PHP 5.3):   
https://bugs.php.net/fix.php?id=64206&r=trysnapshot53
Try a snapshot (trunk):     
https://bugs.php.net/fix.php?id=64206&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=64206&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=64206&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=64206&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=64206&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=64206&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=64206&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=64206&r=notwrong
Not enough info:            
https://bugs.php.net/fix.php?id=64206&r=notenoughinfo
Submitted twice:            
https://bugs.php.net/fix.php?id=64206&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=64206&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=64206&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=64206&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=64206&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=64206&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=64206&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=64206&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=64206&r=mysqlcfg

Reply via email to