php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45199 Serializing objects with private properties
Submitted: 2008-06-07 09:02 UTC Modified: 2009-07-09 20:36 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: mehran20 at hotmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.*, 6CVS (2009-04-25) OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mehran20 at hotmail dot com
New email:
PHP Version: OS:

 

 [2008-06-07 09:02 UTC] 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] => )

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-07-09 20:36 UTC] jani@php.net
See bug #30659
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 15:01:34 2025 UTC