Advertisement
Guest User

PHP Bug #62189

a guest
Jun 4th, 2012
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.38 KB | None | 0 0
  1. <?php
  2.  
  3. class Widget implements Serializable
  4. {
  5.     public $references = array();
  6.     public $config;
  7.  
  8.     public function serialize()
  9.     {
  10.         $vars = get_object_vars($this);
  11.  
  12.         $vars['config'] = serialize($vars['config']);
  13.  
  14.         $serialized = serialize($vars);
  15.  
  16.         return $serialized;
  17.     }
  18.  
  19.     public function unserialize($serialized)
  20.     {
  21.         $array = unserialize($serialized);
  22.  
  23.         $array['config'] = unserialize($array['config']);
  24.  
  25.         foreach($array as $k => $v)
  26.         {
  27.             $this->$k = $v;
  28.         }
  29.     }
  30. }
  31.  
  32. class Placeholder
  33. {
  34.     public $id;
  35.  
  36.     public function __construct($id)
  37.     {
  38.         $this->id = $id;
  39.     }
  40. }
  41.  
  42. $collection = array();
  43.  
  44. $placeholder1 = new Placeholder(1);
  45. $placeholder2 = new Placeholder(2);
  46.  
  47. $widget1 = new Widget;
  48. $widget1->config = array('id_section' => 9);
  49. $widget1->references[] = $placeholder1;
  50.  
  51. $widget2 = new Widget;
  52. $widget2->config = array('id_section' => 9);
  53. $widget2->references[] = $placeholder2;
  54.  
  55. $widget3 = new Widget;
  56. $widget3->config = array('id_section' => 9);
  57. $widget3->references[] = $placeholder1;
  58.  
  59. $widget4 = new Widget;
  60. $widget4->config = array('id_section' => 9);
  61. $widget4->references[] = $placeholder1;
  62.  
  63. $collection[] = $widget1;
  64. $collection[] = $widget2;
  65. $collection[] = $widget3; // reference to placeholder will be missing here
  66. $collection[] = $widget4; // reference to placeholder will be missing here
  67.  
  68. print_r(unserialize(serialize($collection)));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement