Bug #65806 [Opn->Nab]: unserialize fails with object which is referenced multiple times
| From: | mike@php.net | Date: | Fri, 04 Oct 2013 14:02:47 +0000 |
| Subject: | Bug #65806 [Opn->Nab]: unserialize fails with object which is referenced multiple times | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-182025@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=65806&edit=1
ID: 65806
Updated by: mike@php.net
Reported by: sysadmin at interexa dot de
Summary: unserialize fails with object which is referenced
multiple times
-Status: Open
+Status: Not a bug
Type: Bug
Package: *General Issues
Operating System: linux
PHP Version: 5.4.20
Block user comment: N
Private report: N
New Comment:
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
The serialization context is reset and non-recursive in __sleep and __wakeup, so if you serialize
something in __sleep, you have to unserialize it in __wakeup.
Previous Comments:
------------------------------------------------------------------------
[2013-10-02 07:56:18] sysadmin at interexa dot de
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 this bug report at https://bugs.php.net/bug.php?id=65806&edit=1