note 73548 added to language.oop5.magic
| From: | david at bagnara dot org | Date: | Wed, 28 Feb 2007 21:08:02 +0000 |
| Subject: | note 73548 added to language.oop5.magic | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-123965@lists.php.net to get a copy of this message | ||
I am buggered if I know how to make __sleep() work. If there are private members in base classes, it
seems impossible to get them saved.
Example: serializing x will save and restore the a_priv variable
class a { private $a_priv } ;
class b extends a {} ;
x = new b() ;
but add a __sleep() function to class b, which should return an array of variables to save,
function __sleep(){ return array( "a_priv" ) ; }
does not work.
I have tried heaps of things e.g. array_keys((array)$this) as suggested below, get_object_vars(),
get_class_vars() but cannot get that damned private variable saved.
As a side note, also watch out for variables containing references when serializing classes!!
----
Server IP: 203.220.0.234
Probable Submitter: 220.237.187.216
----
Manual Page -- http://www.php.net/manual/en/language.oop5.magic.php
Edit -- https://master.php.net/note/edit/73548
Del: integrated -- https://master.php.net/note/delete/73548/integrated
Del: useless -- https://master.php.net/note/delete/73548/useless
Del: bad code -- https://master.php.net/note/delete/73548/bad+code
Del: spam -- https://master.php.net/note/delete/73548/spam
Del: non-english -- https://master.php.net/note/delete/73548/non-english
Del: in docs -- https://master.php.net/note/delete/73548/in+docs
Del: other reasons-- https://master.php.net/note/delete/73548
Reject -- https://master.php.net/note/reject/73548
Search -- https://master.php.net/manage/user-notes.php