note 62860 added to function.serialize

From: Date: Sat, 11 Mar 2006 02:26:38 +0000
Subject: note 62860 added to function.serialize
Groups: php.notes 
Request: Send a blank email to php-notes+get-105255@lists.php.net to get a copy of this message
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) { } ---- Server IP: 203.220.0.234 Probable Submitter: 125.62.65.184 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.serialize.php Edit -- http://master.php.net/note/edit/62860 Del: integrated -- http://master.php.net/note/delete/62860/integrated Del: useless -- http://master.php.net/note/delete/62860/useless Del: bad code -- http://master.php.net/note/delete/62860/bad+code Del: spam -- http://master.php.net/note/delete/62860/spam Del: non-english -- http://master.php.net/note/delete/62860/non-english Del: in docs -- http://master.php.net/note/delete/62860/in+docs Del: other reasons-- http://master.php.net/note/delete/62860 Reject -- http://master.php.net/note/reject/62860 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#105255) next »