In my project, I'm using class inheritance a lot. Now I notice that my magic getter is not triggering when I want to access a variable in the base class. Hence the following code:
abstract class A
{
protected $varA;
final public function __get($var)
{
echo $var;
}
}
class B extends A
{
protected $varB;
}
class C extends A
{
public function test()
{
$test = new B();
$test->varB; // Get output
$test->varA; // No output
}
}
$test = new C();
$test->test();
Now I see that you faced with php feature. Visibility of properties relies on classes but not on the objects.
Objects of the same type will have access to each others private and protected members even though they are not the same instances. This is because the implementation specific details are already known when inside those objects.
http://php.net/manual/en/language.oop5.visibility.php#example-208