Advertisement
Guest User

Untitled

a guest
Apr 12th, 2009
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.68 KB | None | 0 0
  1. <?php
  2. class Foo {
  3.     function __construct (&$arr) {
  4.         $this->arr = &$arr;
  5.     }
  6.     function createInstance () {
  7.         $reflectionClass = new ReflectionClass("Bar");
  8.        
  9.         return $reflectionClass->newInstanceArgs(array($this, $this->arr));
  10.     }
  11.     function mod($key, $val) {
  12.         $this->arr[$key] = $val;
  13.     }
  14. }
  15.  
  16. class Bar {
  17.     function __construct (&$foo, &$arr) {
  18.         $this->foo = &$foo;
  19.         $this->arr = &$arr;
  20.     }
  21.     function mod($key, $val) {
  22.         $this->arr[$key] = $val;
  23.     }
  24. }
  25.  
  26. $arr = array();
  27.  
  28. $foo = new Foo($arr);
  29.  
  30. $arr["x"] = 1;
  31.  
  32. $foo->mod("y", 2);
  33.  
  34. $bar = $foo->createInstance();
  35.  
  36. $bar->mod("z", 3);
  37.  
  38. echo "<pre>";
  39. print_r($arr);
  40. print_r($foo);
  41. print_r($bar);
  42. echo "</pre>";
  43. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement