Bug #71940 [Csd]: Unserialize crushes on restore object reference
| From: | oparkhomenko at magecore dot com | Date: | Thu, 07 Apr 2016 13:10:34 +0000 |
| Subject: | Bug #71940 [Csd]: Unserialize crushes on restore object reference | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-200424@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=71940&edit=1
ID: 71940
User updated by: oparkhomenko at magecore dot com
Reported by: oparkhomenko at magecore dot com
Summary: Unserialize crushes on restore object reference
Status: Closed
Type: Bug
Package: Class/Object related
Operating System: Debian
PHP Version: 7.0Git-2016-04-01 (Git)
Block user comment: N
Private report: N
New Comment:
What stable version will include this fix ?
Previous Comments:
------------------------------------------------------------------------
[2016-04-07 05:58:25] laruence@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=7e042224a26282938b866a49ca3d4af1b368c0cc
Log: Fixed bug #71940 (Unserialize crushes on restore object reference)
------------------------------------------------------------------------
[2016-04-01 11:18:38] oparkhomenko at magecore dot com
Description:
------------
The PHP version 7.0.0 and over can't restore object that was serialized as reference.
Test script:
---------------
<?php
class Identity
{
private $role;
public function __construct($role)
{
$this->role = $role;
}
}
class Entry implements \Serializable
{
private $identity;
public function __construct(Identity $identity)
{
$this->identity = $identity;
}
public function serialize()
{
return serialize(array($this->identity));
}
public function unserialize($serialized)
{
list($this->identity) = unserialize($serialized);
}
}
$identity = new Identity('test');
$identityRef = &$identity;
$entry1 = new Entry($identity);
$entry2 = new Entry($identityRef);
$serialized = serialize([$entry1, $entry2]);
print_r(unserialize($serialized));
?>
Expected result:
----------------
Array
(
[0] => Entry Object
(
[identity:Entry:private] => Identity Object
(
[role:Identity:private] => test
)
)
[1] => Entry Object
(
[identity:Entry:private] => Identity Object
(
[role:Identity:private] => test
)
)
)
Actual result:
--------------
PHP Notice: unserialize(): Error at offset 13 of 14 bytes in /opt/dev/test/Test.php on line 29
PHP Stack trace:
PHP 1. {main}() /opt/dev/test/Test.php:0
PHP 2. unserialize() /opt/dev/test/Test.php:40
PHP 3. Entry->unserialize() /opt/dev/test/Test.php:40
PHP 4. unserialize() /opt/dev/test/Test.php:29
Array
(
[0] => Entry Object
(
[identity:Entry:private] => Identity Object
(
[role:Identity:private] => test
)
)
[1] => Entry Object
(
[identity:Entry:private] =>
)
)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71940&edit=1