Ive been learning PHP for the last week and have looked at the same piece of code several times but still dont quite understand it.
Heres an example.
class firstObject{
public $var1 = 'First Variable';
public $var2 = 'Second Variable';
}
class secondObject{
protected $objArray = array();
function addObj($obj) {
$this->objArray = $obj;
}
function getObj(){
return 'The ' . $this->objArray->var1 . ' and the ' . $this->objArray->var2 . '.';
}
}
$first = new firstObject;
$sec = new secondObject;
$sec->addObj($first);
echo $sec->getObj();
The way i understand it the object is stored in an array as though its a multi dimensional array. So therefore i should be able to assign a key to each object within the array. But when i try this it doesn’t work. If someone could explain the concept here for me it would be greatly appreciated.
Many Thanks
George