Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Widget implements Serializable
- {
- public $references = array();
- public $config;
- public function serialize()
- {
- $vars = get_object_vars($this);
- $vars['config'] = serialize($vars['config']);
- $serialized = serialize($vars);
- return $serialized;
- }
- public function unserialize($serialized)
- {
- $array = unserialize($serialized);
- $array['config'] = unserialize($array['config']);
- foreach($array as $k => $v)
- {
- $this->$k = $v;
- }
- }
- }
- class Placeholder
- {
- public $id;
- public function __construct($id)
- {
- $this->id = $id;
- }
- }
- $collection = array();
- $placeholder1 = new Placeholder(1);
- $placeholder2 = new Placeholder(2);
- $widget1 = new Widget;
- $widget1->config = array('id_section' => 9);
- $widget1->references[] = $placeholder1;
- $widget2 = new Widget;
- $widget2->config = array('id_section' => 9);
- $widget2->references[] = $placeholder2;
- $widget3 = new Widget;
- $widget3->config = array('id_section' => 9);
- $widget3->references[] = $placeholder1;
- $widget4 = new Widget;
- $widget4->config = array('id_section' => 9);
- $widget4->references[] = $placeholder1;
- $collection[] = $widget1;
- $collection[] = $widget2;
- $collection[] = $widget3; // reference to placeholder will be missing here
- $collection[] = $widget4; // reference to placeholder will be missing here
- print_r(unserialize(serialize($collection)));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement