Just figured out another way to get around the multiple-copies problem.
Keep classes B and C independent of A (i.e., no extends) but pass the object A to these
classes so that they will know what is going on in A. Here is how this would work:
class A
{
var $varA;
function A ()
{
$Bobj = new B($this); // Call the B constructor with the object A
$Cobj = new C($this); // Call the C constructor with the object B
}
function funcA()
{
.... some stuff
}
}
class B
{
var $varB;
var $Aobj;
function B($obj)
{
$this->Aobj = &$obj; //B can now access A via $this->Aobj->(... properties, methods, etc.)
}
function funcB()
{
... some more stuff
}
}
class C
{
var $varC;
var $Aobj;
function C($obj)
{
$this->Aobj = &$obj; //C can now access A similarly
}
}
This now makes it possible for both B and C, which could be completely unrelated objects,
to access a "base" class A. Class A, for example, might have common error handling routines
for the entire site, and now subordinate classes can access that code without worrying about
whether there are multiple copies of variables running around.
The solution that van proposes (basically using global variables) will work, but if you want
to centralize some functionality, then you need to do something like this or keep stacking up
inheritances (C extends B , B extends A) etc.
I haven't tried Diego's solution (static variables), but that wouldn't resolve the need to use the
same functions from multiple classes, anyway.