I want to get an instance of an existing object. How do I do this without having to pass the object as a parameter? This is what I'm doing now:
class clas1 {
public $myArray;
public function setArray($a){
$this->myArray = $a;
}
}
class clas2 {
public $test;
function __construct($obj) {
$this->test = $obj;
}
}
$c = new clas1;
$c->setArray(array('firstname'=>'Fred'));
$c2 = new clas2($c);
var_dump($c2);
The output of var_dump is:
object(clas2)[2]
public 'test' =>
object(clas1)[1]
public 'myArray' =>
array
'firstname' => string 'Fred' (length=4)
I suppose I could have each object as a property of a parent object, but is are there any other suggestions?