An instance of class A instantiates a couple of other objects, say for example from class B:
$foo = new B();
I would like to access A’s public class variables from methods within B.
Unless I’m missing something, the only way to do this is to pass the current object to the instances of B:
$foo = new B($this);
Is this best practice or is there another way to do this?
That looks fine to me, I tend to use a rule of thumb of ‘would someone maintaining this understand it?’ and that’s an easily understood solution.
If there’s only one ‘A’, you could consider using the registry pattern, see for example http://www.phppatterns.com/docs/design/the_registry