|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2016-12-30 23:57 UTC] cmb@php.net
-Package: Feature/Change Request
+Package: Variables related
[2020-12-07 15:00 UTC] cmb@php.net
-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: cmb
[2020-12-07 15:00 UTC] cmb@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 30 03:00:01 2025 UTC |
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;}