#45199 [Opn->Asn]: Serializing objects with private properties

From: Date: Sun, 06 Jul 2008 11:50:29 +0000
Subject: #45199 [Opn->Asn]: Serializing objects with private properties
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-126313@lists.php.net to get a copy of this message
ID: 45199 Updated by: jani@php.net Reported By: mehran20 at hotmail dot com -Status: Open +Status: Assigned Bug Type: Class/Object related Operating System: CentOS / Linux PHP Version: 5.2.6 -Assigned To: +Assigned To: helly New Comment: Marucs: Another PPP issue. Previous Comments: ------------------------------------------------------------------------ [2008-06-07 09:02:39] mehran20 at hotmail dot com Description: ------------ Hi Before you read the code, I want to say that the code that is given in this section works fine. The only problem is for the code that is given in the "Reproduce code". class A { private $a = 1; } class B extends A { private $b = 2; } $v = new B; print_r(unserialize(serialize($v))); Output (which is correct): B Object ( [b:private] => 2 [a:private] => 1 ) Reproduce code: --------------- class A { private $a = 1; public function __sleep() { $vars = get_object_vars($this); return array_keys($vars); } } class B extends A { private $b = 2; } $v = new B; print_r(unserialize(serialize($v))); Expected result: ---------------- B Object ( [b:private] => 2 [a:private] => 1 ) Or B Object ( [b:private] => 2 ) I prefer the first one! But both could be correct!! Actual result: -------------- Notice: serialize() [function.serialize]: "a" returned as member variable from __sleep() but does not exist in <__FILE__> on line 14 B Object ( [b:private] => 2 [a:private] => 1 [a] => ) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=45199&edit=1

« previous php.bugs (#126313) next »