Example of setting up static property in child class from parent only if it isn't already defined, many people would expect that output will be "Foo Bar" but instead we get "Foo Foo":
<?php
class Foo
{
public static string $A;
public static function init() {
return "Foo";
}
public static function get() {
if (!isset(static::$A)) {
static::$A = static::init();
}
return static::$A;
}
}
class Bar extends Foo {
public static function init() {
return "Bar";
}
}
$foo = new Foo();
$bar = new Bar();
echo $foo->get();
echo $bar->get();
?>
Output:
Foo
Foo