Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Foo {
- function __construct (&$arr) {
- $this->arr = &$arr;
- }
- function createInstance () {
- $reflectionClass = new ReflectionClass("Bar");
- return $reflectionClass->newInstanceArgs(array($this, $this->arr));
- }
- function mod($key, $val) {
- $this->arr[$key] = $val;
- }
- }
- class Bar {
- function __construct (&$foo, &$arr) {
- $this->foo = &$foo;
- $this->arr = &$arr;
- }
- function mod($key, $val) {
- $this->arr[$key] = $val;
- }
- }
- $arr = array();
- $foo = new Foo($arr);
- $arr["x"] = 1;
- $foo->mod("y", 2);
- $bar = $foo->createInstance();
- $bar->mod("z", 3);
- echo "<pre>";
- print_r($arr);
- print_r($foo);
- print_r($bar);
- echo "</pre>";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement