Static Properties¶
<?php
class Test {
public static $x = 0;
}
class Test2 extends Test {
// $x is inherited
}
class Test3 extends Test {
// $x is NOT inherited
public static $x = 3;
}
$x = 1;
Test2::$x = &$x;
var_dump(Test::$x, Test2::$x, Test3::$x);
// int(1), int(1), int(3)
?>
It is easy to read that the property $x is of type Test (via static), with an impossible default value of 0. In fact, this property is not typed, as using static is not a possible type for properties.
Secondly, static properties are inherited and shared with the parent static properties, unless they are declared again. In that case, they are distinct.
See Also¶
Static Properties on 3v4l [Try me]
PHP Features¶
Last updated: 14 July 2026