Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class testClass_forSerialize implements Serializable{
- public function serialize()
- {
- $ret = new \stdClass();
- foreach($this as $k=>$v){
- if ($v!==null) {
- $ret->{$k} = $v;
- }
- }
- $serializedData = serialize($ret);
- if (unserialize($serializedData)===false) {
- var_dump($serializedData);
- throw new \Exception("Serialize failed");
- }
- return $serializedData;
- }
- public function unserialize($data)
- {
- $dataObj = unserialize($data);
- foreach($dataObj as $k=>$v) {
- $this->{$k} = $v;
- }
- }
- }
- class testClass_forSerialize_02 extends \testClass_forSerialize{
- public $list = Array();
- public function __construct()
- {
- for ($i=0; $i<10; $i++) {
- $this->list[] = new \testClass_forSerialize();
- }
- }
- }
- $obj = new \testClass_forSerialize_02();
- $ser = serialize($obj);
- $obj2 = unserialize($ser);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement