|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2016-04-07 05:58 UTC] laruence@php.net
[2016-04-07 05:58 UTC] laruence@php.net
-Status: Open
+Status: Closed
[2016-04-07 13:10 UTC] oparkhomenko at magecore dot com
[2016-07-20 11:32 UTC] davey@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 02:00:01 2025 UTC |
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] => ) )