php.net |  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: 2016-12-30 23:57 UTC
Votes:14
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:
Status: Open Package: Variables related
PHP Version: 5.2.1RC4 OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2007-02-09 09:17 UTC] denis at edistar dot com
Description:
------------
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 
error:

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() {
                parent::__construct();
        }

}


$obj = new D();

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


?>


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

O:1:"D":1:{s:15:"privateProperty";s:7:"myValue";}



Actual result:
--------------
Notice: serialize(): "privateProperty" returned as member 
variable from __sleep() but does not exist in test.php on 
line 30
O:1:"D":1:{s:15:"privateProperty";N;}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-12-30 23:57 UTC] cmb@php.net
-Package: Feature/Change Request +Package: Variables related
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Tue Aug 20 08:01:28 2019 UTC