|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #40412 __sleep should return private parent members
Submitted: 2007-02-09 09:17 UTC Modified: 2020-12-07 15:00 UTC
Avg. Score:3.9 ± 0.9
Reproduced:13 of 13 (100.0%)
Same Version:0 (0.0%)
Same OS:5 (38.5%)
From: denis at edistar dot com Assigned: cmb (profile)
Status: Closed Package: Variables related
PHP Version: 5.2.1RC4 OS: Linux
Private report: No CVE-ID: None
 [2007-02-09 09:17 UTC] denis at edistar dot com
I have two classes: 
- one parent with a private property
- one child that extends the parent

When i serialize the child property I get the following 

Notice: serialize(): "privateProperty" returned as member 
variable from __sleep() but does not exist in test.php on 
line 30

I already know of serializable interface. But the problem 
still persist also using this interface... 
If I define a serialize method in the parent class, 
get_object_vars and reflection api do not return the 
privateProperty value... they continue to think we are 
into the scope of the child class (when we are instead 
into the parent class).

Reproduce code:

class P {

        private $privateProperty;

        public function __construct() {
                $this->privateProperty = "myValue";

        public function __sleep() {

                return array('privateProperty');


class D extends P {

        public function __construct() {


$obj = new D();

$s = serialize($obj);
echo $s;


Expected result:
I expect no warning should be raised and the echo should 
print this:


Actual result:
Notice: serialize(): "privateProperty" returned as member 
variable from __sleep() but does not exist in test.php on 
line 30


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-12-30 23:57 UTC]
-Package: Feature/Change Request +Package: Variables related
 [2020-12-07 15:00 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2020-12-07 15:00 UTC]
Use __serialize()[1] instead (Serializable should also work, but
has other known issues).

[1] <>
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Sep 27 06:03:38 2021 UTC