fork download
  1. <?php
  2.  
  3. class Container {
  4. private $data = array();
  5.  
  6. public function get($key) {
  7. return $this->data[$key];
  8. }
  9.  
  10. public function set($key, $obj) {
  11. $this->data[$key] = $obj;
  12. }
  13. }
  14.  
  15. $o = new StdClass();
  16. $o->x = 123;
  17.  
  18.  
  19. $c = new Container();
  20. $c->set('o', $o);
  21.  
  22. $o->x = 321;
  23.  
  24. var_dump($c->get('o'));
  25.  
  26. $c->get('o')->x = 333;
  27.  
  28.  
  29. $c->set('o2', $o);
  30. $c->set('o3', $o);
  31.  
  32. $o->x = 1;
  33.  
  34. var_dump($c->get('o2'), $c->get('o3'));
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
object(stdClass)#1 (1) {
  ["x"]=>
  int(123)
}
object(stdClass)#1 (1) {
  ["x"]=>
  int(321)
}
object(stdClass)#1 (1) {
  ["x"]=>
  int(333)
}
object(stdClass)#1 (1) {
  ["x"]=>
  int(1)
}
object(stdClass)#1 (1) {
  ["x"]=>
  int(1)
}