php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71838 Deserializing serialized SPLObjectStorage-Object can't access properties in PHP
Submitted: 2016-03-16 15:16 UTC Modified: 2016-03-16 15:22 UTC
From: andreas at heigl dot org Assigned:
Status: Closed Package: SPL related
PHP Version: 7.0.4 OS: 3v4l.org
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: andreas at heigl dot org
New email:
PHP Version: OS:

 

 [2016-03-16 15:16 UTC] andreas at heigl dot org
Description:
------------
It seems that with PHP7 (and HHVM) deserializing a serialized SPLObjectStorage-Object results in an Object that can not access the properties any more. The properties seem to be there (somehow) as a "var_Dump($obj)" shows them, but methods from inside the newly created object can't access those values any more.

I've created a test-script at https://3v4l.org/LCmI2 to illustrate the case.

Am I missing something? I could not find a reference to this behaviour but I might just not have searched for the right terms...

Test script:
---------------
<?php

class A extends SplObjectStorage 
{
    protected $a = null;

    public function __construct()
    {
        $this->a = '123';
    }
    
    public function getA()
    {
        return $this->a;
    }
}

$serialized = serialize(new A());
$obj = unserialize($serialized);

$reader = function & ($object, $property) {
    $value = & \Closure::bind(function & () use ($property) {
        return $this->$property;
    }, $object, $object)->__invoke();

    return $value;
};

$test3 = & $reader($obj, 'a');

echo "Result from Getter\n";
var_dump($obj->getA());

echo "Result from Reflection\n";
var_Dump($test3);

echo "This is the deserialized Object\n";
var_Dump($obj);

Expected result:
----------------
I'd expect the same output in PHP7 as in PHP5.6


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-03-16 15:21 UTC] andreas at heigl dot org
-Summary: Deserializing serialized SPLObjectStorage-Object can't access properties in PHP +Summary: 39
 [2016-03-16 15:21 UTC] andreas at heigl dot org
Removing the "extends SPLObjectStorage" fixes the issue as can be seen at https://3v4l.org/SjBmY
 [2016-03-16 15:22 UTC] andreas at heigl dot org
-Summary: 39 +Summary: Deserializing serialized SPLObjectStorage-Object can't access properties in PHP
 [2016-03-16 15:22 UTC] andreas at heigl dot org
-
 [2016-03-18 19:00 UTC] nikic@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=094c80837440963872368e81188b58d7c7d214fa
Log: Fix bug #71838
 [2016-03-18 19:00 UTC] nikic@php.net
-Status: Open +Status: Closed
 [2016-07-20 11:32 UTC] davey@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=094c80837440963872368e81188b58d7c7d214fa
Log: Fix bug #71838
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Oct 14 09:01:27 2024 UTC