Hi guys, I need to track which instance created another instance. It's an instancing hierarchy not a parent-child class hierarchy. Here's an example:
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;
}
}
if I do:
$myCar1 = new Car();
$myEngine = new Engine(200);
I currently have 1 instance of Car and 2 of Engine. I need to know which instance created which instance. something like this:
$creator = instanceCreatorOf($myCar1->engine or $myCar1->engine->id);
would return: $myCar or $myCar->id;
but if I do:
$creator = instanceCreatorOf($myEngine or $myEngine->id);
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!