Referring to a static subclass element

I want to have a sub keyword that would make the code below print value on execution. Does not exist, and I am wondering - is there an existing way to refer to a member of a subclass?

 class Main { static function foo() { echo sub::$variable; } } class Sub extends Main { static $variable = "value"; } Sub::foo(); 
+2
source share
1 answer

I think you are looking for static::$variable . This is called Late Static Binding and is available since PHP 5.3.

+7
source

Source: https://habr.com/ru/post/1392320/


All Articles