Bug #76300 [Ver->Csd]: Serialize/Unserialize of extended protected member broken

From: Date: Sun, 17 Jun 2018 22:53:38 +0000
Subject: Bug #76300 [Ver->Csd]: Serialize/Unserialize of extended protected member broken
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-215765@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 Updated by: stas@php.net Reported by: rishad at kaluma dot com Summary: Serialize/Unserialize of extended protected member broken -Status: Verified +Status: Closed 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: Automatic comment on behalf of mail@pmmaga.net Revision: http://git.php.net/?p=php-src.git;a=commit;h=2dca8671e4590917a52a4cd9cb57951b412e2f95 Log: Fix #76300 - Dont attempt to change visibility of a parent private Previous Comments: ------------------------------------------------------------------------ [2018-05-03 20:31:14] pmmaga@php.net I have opened a PR for the fix: https://github.com/php/php-src/pull/3233 ------------------------------------------------------------------------ [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

« previous php.bugs (#215765) next »