SHARE
TWEET

bug #1

a guest Feb 18th, 2015 199 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. class testClass_forSerialize implements Serializable{
  3.         public function serialize()
  4.         {
  5.            
  6.                 $ret = new \stdClass();
  7.         foreach($this as $k=>$v){
  8.                 if ($v!==null) {
  9.                                 $ret->{$k} = $v;
  10.                 }
  11.         }
  12.        
  13.                 $serializedData = serialize($ret);
  14.  
  15.                 if (unserialize($serializedData)===false) {
  16.                         var_dump($serializedData);
  17.                 throw new \Exception("Serialize failed");
  18.         }
  19.  
  20.                 return $serializedData;
  21.         }
  22.  
  23.         public function unserialize($data)
  24.         {
  25.                 $dataObj = unserialize($data);
  26.                 foreach($dataObj as $k=>$v) {
  27.                         $this->{$k} = $v;
  28.                 }
  29.         }
  30. }
  31.  
  32.  
  33. class testClass_forSerialize_02 extends \testClass_forSerialize{
  34.         public $list = Array();
  35.  
  36.         public function __construct()
  37.         {
  38.                 for ($i=0; $i<10; $i++) {
  39.                         $this->list[] = new \testClass_forSerialize();
  40.                 }
  41.         }
  42. }
  43.  
  44.  
  45. $obj = new \testClass_forSerialize_02();
  46.  
  47. $ser = serialize($obj);
  48. $obj2 = unserialize($ser);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top