From:             sysadmin at interexa dot de
Operating system: linux
PHP version:      5.4.20
Package:          *General Issues
Bug Type:         Bug
Bug description:unserialize fails with object which is referenced multiple times

Description:
------------
Running the testscript fails. The second reference to Object A is null
after unserialize.
This happens in PHP 5.4.x as well as  PHP 5.5.4.

Maybe this bug is related to bug 65724. 

Test script:
---------------
<?php
class myObjA {}
class myObjB {
    public $attrA;
    public $attrB;
}
class myObjC {
    public $attrC;
    public $attrD;
}
class myList {
    private $_serialized;
    private $_obj;

    public function __construct($obj)
    {
        $this->_obj = $obj;
        $this->_serialized = serialize($this->_obj);
    }
    public function get()
    {
        return unserialize($this->_serialized);
    }
    public function __sleep()
    {
        $this->_serialized = serialize($this->_obj);
        return array(
            "\0" . __CLASS__ . "\0_serialized",
        );
    }
}

echo "SCRIPT START" . PHP_EOL;

$objA = new myObjA();
$objB = new myObjB();
$objC = new myObjC();

$objB->attrA = new ArrayIterator();
$objB->attrB = $objA;

$objC->attrC = $objB;
$objC->attrD = $objA;

$list = new myList($objC);

echo 'check ' . check($list->get()) . PHP_EOL;

file_put_contents('serialize.dmp', serialize($list));

echo "start serialize/unserialize" . PHP_EOL;
$newList = unserialize(serialize($list));
echo "finish serialize/unserialize" . PHP_EOL;

//after unserialize the property myObjC::attrD is null instead of
expected object
echo 'check ' . check($newList->get()) . PHP_EOL;

echo "SCRIPT END" . PHP_EOL ;

function check(myObjC $obj) {

    if (!is_object($obj->attrC)) {
        return 'failed (myObjC::attrC => ' . var_export($obj->attrC,
true) . ')';
    }
    if (!is_object($obj->attrD)) {
        return 'failed (myObjC::attrD => ' . var_export($obj->attrD,
true) . ')';
    }
    return 'successful';
}

Expected result:
----------------
SCRIPT START
check successful
start serialize/unserialize
finish serialize/unserialize
check successful
SCRIPT END


Actual result:
--------------
SCRIPT START
check successful
start serialize/unserialize
finish serialize/unserialize
check failed (myObjC::attrD => NULL)
SCRIPT END


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

Reply via email to