note 73548 rejected from language.oop5.magic by bobby

From: Date: Wed, 28 Feb 2007 21:16:50 +0000
Subject: note 73548 rejected from language.oop5.magic by bobby
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-123966@lists.php.net to get a copy of this message
Note Submitter: david at bagnara dot org ---- 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!!

« previous php.notes (#123966) next »