Bug #71940 [NEW]: Unserialize crushes on restore object reference

From: Date: Fri, 01 Apr 2016 11:18:43 +0000
Subject: Bug #71940 [NEW]: Unserialize crushes on restore object reference
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-200284@lists.php.net to get a copy of this message
From:             oparkhomenko at magecore dot com
Operating system: Debian
PHP version:      7.0Git-2016-04-01 (Git)
Package:          Class/Object related
Bug Type:         Bug
Bug description:Unserialize crushes on restore object reference

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



Thread (3 messages)

« previous php.bugs (#200284) next »