I think my title about says it all. During the __construct()
-tion of $classA
, $classB
is instantiated. When $classB
is instantiated it needs to access to another class inside $classA
(i.e. $classA->classC
). $classC
has already been instantiated in $classA
.
Inside the __construct() function of $classB
I am attempting to do something like Global $classA;
so that I can get something from $classA->classC->method()
. Obviously $classA
hasn't completed instantiation yet so it isn't available to be imported from the Global scope.
What I have done to work around not being able to access $classA
via Global is to pass $this
as an argument to $classB
when it is instantiated in $classA
. This is messy but it works. I would like to try to avoid the messy-ness and hackish feel of passing $this.
Does anyone have any ideas how to better accomplish what I am trying to do?
I know that this is kind of complex so if anyone has any ideas how I could clarify it I will be happy to oblige!