Based on your questions, it sounds like you may be misunderstanding the distinction between classes and objects. Think of the class as a specification from which objects are created. You aren't really going to be manipulating classes in your code, you're going to be creating objects from those classes and working with those instances of the classes. Classes like the ones you've shown aren't really anything until they're instantiated.
When you create an instance of class C
with $c = new C;
, the resulting object $c
will have access to all of the public and protected properties of any classes it inherits from; in this case A
and B
. Those properties are accessible anywhere in the C
class. You can access them with $this->varA
, for example.
But the way you have it written, none of the classes have any public properties or methods. So any code you write that uses them isn't going to have access to any of the properties. protected
means that the property or method will only be available within the class or classes that inherit from it. So after $c = new C;
, you won't be able to call $c->functionC()
, and you won't be able to refer to $->varA
, or even $c->varC
.
If you create an instance of A
and an instance of C
, those two objects are completely independent of each other. The instance of C
has its own $varA
, and if you change the $varA
in the instance of A
, it will not affect the instance of C
.
Here are a couple of example classes with public methods to demonstrate this.
class A {
protected $varA = 'a';
public function changeA ($newValue) {
$this->varA = $newValue;
}
}
class B extends A {
public function example()
{
echo $this->varA;
}
}
If you create a new B, its example
method will show the inherited value in $varA
.
$instanceOfB = new B;
$instanceOfB->example(); // outputs a
Then if you create a new A
, and change the value of its $varA
...
$instanceOfA = new A;
$instanceOfA->changeA('something else'); // varA in this object is modified
The value of $varA
in the instance of B
is unaffected.
$instanceOfB->example(); // still outputs a
I just used one level of inheritance in the example, but the concept is the same with a A/B/C setup you showed.