From:             niko dot sams at gmail dot com
Operating system: Linux
PHP version:      5.5.4
Package:          *General Issues
Bug Type:         Bug
Bug description:unserialize doesn't always restore referenced objects

Description:
------------
when doing another unserialize that creates objects in an 
Serializable::unserialize implementation things break, the 'parent' isn't 
unserialized correctly.

ok: PHP 5.3.3-7+squeeze14
ok: PHP 5.3.10-1ubuntu3.6
fail: PHP 5.4.4-14+deb7u2
fail: PHP 5.5.3

See phpt test script:
http://paste.kde.org/p83ce39d0/

Test script:
---------------
class Bar {}
class Foo implements Serializable {
    public $test;
    public function __construct($test) { $this->test = $test; }
    public function serialize()
    {
        return $this->test;
    }
    public function unserialize($serialized)
    {
        //the following line causes problems
        unserialize('O:3:"Bar":1:{s:4:"bar1";O:3:"Bar":0:{}}');
        $this->test = $serialized;
    }
}
$foo1 = new Foo('foo1');
$foo2 = new Foo('foo2');
$foo3 = new Foo('foo3');
$ar = array(
    array(
        'instance' => $foo1,
    ),
    array(
        'instance' => $foo2,
    ),
    array(
        'instance' => $foo3,
        'parent' => $foo2
    )
);
$ar = serialize($ar);
$ar = unserialize($ar);
print_r($ar);

Expected result:
----------------
[parent] => Foo Object ( [test] => foo2 ) )

Actual result:
--------------
[parent] => foo2

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

Reply via email to