Inheritance works at create time, i.e. using the keyword 'new'. Static properties confused my understanding, so in order tho show the effect of visibility to inherintence I've created a simple demo script along with some set and get magic:
<?php
class A {
private $a = 'private';
protected $b = 'protected';
public $c = 'public';
static $d = 'static';
public function __construct()
{
$this->e = 'constructed';
}
public function __set($property, $value)
{
echo ' set ' . $property . '=' . $value;
$this->$property=$value;
}
public function __get($property)
{
echo ' get ' . $property;
$this->$property = 'dynamic'; return $this->$property;
}
}
class B extends A
{
public function constructMe()
{
$this->e = 'constructed2';
}
}
class C extends B
{
public function __construct()
{
parent::constructMe();
}
}
echo " \n";
$a = new A();
$b = new B();
echo " \n";
echo ' B:c='.$b->c;
echo " \n";
echo ' B:d=' .$b->d;
echo " \n";
$c = new C();
echo " \n";
print_r($a);
print_r($b);
print_r($c);
print_r(A::$d);
print_r(B::$d);
print_r(C::$d);
echo 'A class: ';
$R = new reflectionclass('A');
print_r($R->getdefaultproperties());
print_r($R->getstaticproperties());
echo 'B class: ';
$R = new reflectionclass('B');
print_r($R->getdefaultproperties());
print_r($R->getstaticproperties());
?>
This outputs:
set e=constructed
B:c=public
get d set d=dynamic B:d=dynamic
set e=constructed2
A Object
(
[a:A:private] => private
[b:protected] => protected
[c] => public
[e] => constructed
)
B Object
(
[a:A:private] => private
[b:protected] => protected
[c] => public
[d] => dynamic
)
C Object
(
[a:A:private] => private
[b:protected] => protected
[c] => public
[e] => constructed2
)
staticstaticstaticA class: Array
(
[d] => static
[a] => private
[b] => protected
[c] => public
)
Array
(
[d] => static
)
B class: Array
(
[d] => static
[b] => protected
[c] => public
)
Array
(
[d] => static
)
This shows how private variables ($a) are inherited, how static variables ($d) are inherited (by the class, not by the object) and that changing or adding variables in the parent ($e, $d) are not inherited by the child.