I had some problem formulating the question in the title, but i hope you get me with a bit of example code.
Basically:
In a objectoriented project i want to access an object that is defined in the "parent" object. consider this snippet:
class Bar
{
public $var;
public function Bar()
{
$this->var = 'value';
}
}
class Bogus
{
public function Bogus()
{
//Here i want to access the methods and vars of obj1 in the "parent" object
}
}
class Foo
{
public $obj1,$obj2;
function Foo()
{
$this->obj1 = new Bar();
$this->obj2 = new Bogus();
}
}
as you can see the "child" object are not really childs in the sense that they extend the "parent" class but only objects instanciated inside an object.
is there any "oh damn thats cool" kinda way to do this or do i have to pass the objects to eachother like:
$this->obj2 = new Bogus($this->obj1);
or make use of global object, instanciating objects outside the class:
global $bar,$bogus;
class Foo
{
public $obj1,$obj2;
function Foo()
{
global $bar,$bogus;
$this->obj1 = $bar = new Bar();
$this->obj2 = $bogus = new Bogus();
}
}
I hope you can understand what im getting at ;)