Bug #76300 [Com]: Serialize/Unserialize of extended protected member broken
| From: | pmmaga@php.net | Date: | Thu, 03 May 2018 20:31:15 +0000 |
| Subject: | Bug #76300 [Com]: Serialize/Unserialize of extended protected member broken | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-215046@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76300&edit=1
ID: 76300
Comment by: pmmaga@php.net
Reported by: rishad at kaluma dot com
Summary: Serialize/Unserialize of extended protected member
broken
Status: Verified
Type: Bug
Package: Class/Object related
Operating System: Ubuntu 16.04
PHP Version: 7.2.5
Block user comment: N
Private report: N
New Comment:
I have opened a PR for the fix: https://github.com/php/php-src/pull/3233
Previous Comments:
------------------------------------------------------------------------
[2018-05-03 19:48:46] nikic@php.net
https://3v4l.org/7anY7
Most likely caused by https://github.com/php/php-src/pull/2494.
------------------------------------------------------------------------
[2018-05-03 19:41:08] cedricleong at gmail dot com
This is not the serialize function break, rather you are overriding the base classes variable by
assigning the same scope (protected) and same variable name ($id).
------------------------------------------------------------------------
[2018-05-03 18:57:20] rishad at kaluma dot com
Description:
------------
$php -v
```
PHP 7.2.4-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Apr 5 2018 08:53:57) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.4-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend
Technologies
with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans
```
I have a base class and derived class with same member name.
In the base class if member is protected it breaks the serialize/unserialize.
However, if the member is private functionality works as expected.
This works on:
PHP 7.1.11-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Oct 27 2017 13:49:56) ( NTS )
Test script:
---------------
<?php
class Base {
private $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Derived extends Base {
protected $id;
public function __construct($id)
{
parent::__construct($id + 20);
$this->id = $id;
}
}
$a = new Derived(44);
$s = serialize($a);
$u = unserialize($s);
print_r($u);
Expected result:
----------------
Derived Object
(
[id:protected] => 44
[id:Base:private] => 64
)
Actual result:
--------------
Derived Object
(
[id:protected] => 64
[id:Base:private] =>
)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76300&edit=1