music legend
New Member
I need to track which instance created another instance. It's an instancing hierarchy not a parent-child class hierarchy. Here's an example:\[code\]class Car{ private var $engine; private var $id; public function __construct(){ $this->id = nextId(); $this->engine = new Engine(500); }}class Engine{ private var $horsepower; private var $id; public function __construct($hp){ $this->id = nextId(); $this->horsepower = $hp; }}\[/code\]if I do:\[code\]$myCar1 = new Car();$myEngine = new Engine(200);\[/code\]I currently have 1 instance of Car and 2 of Engine. I need to know which instance created which instance. something like this:\[code\]$creator = instanceCreatorOf($myCar1->engine or $myCar1->engine->id);\[/code\]would return: $myCar or $myCar->id;but if I do:\[code\]$creator = instanceCreatorOf($myEngine or $myEngine->id);\[/code\]would return: root or null or 0;I need to track this but having a lot of dynamically created objects I need dynamic tracking of this hierarchy. Any ideas?thanks!