note 62860 deleted from function.serialize by danbrown

From: Date: Mon, 20 Jun 2011 15:25:01 +0000
Subject: note 62860 deleted from function.serialize by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-180758@lists.php.net to get a copy of this message
Note Submitter: me-no-spam-iain at iaindooley dot com ---- i've just been having fun with the Serializable interface. The big prob is that get_class_vars does not return the current values of the vars, and get_object_vars does not return private members :-( this behaviour was alledgedly fixed in cvs march 2005, but is back again!! i've reported it here: http://bugs.php.net/bug.php?id=36693 the following are serialize and unserialize functions that will allow you to implement the Serializable interface, saving all members' current values and giving any extending classes the opportunity to add in any of their private member variables as well. public function serialize() { $serialized = array(); foreach(array_keys(get_class_vars(__CLASS__)) as $key) eval('$serialized[\''.$key.'\'] = $this->'.$key.';'); $this->serializeMore($serialized); return serialize($serialized); } protected function serializeMore(&$arr) { } public function unserialize($serialized) { $data = unserialize($serialized); foreach($data as $prop => $val) $this->$prop = $val; $this->unserializeMore($data); $this->releaseTable(); return true; } protected function unserializeMore($data) { }

« previous php.notes (#180758) next »