开发者

Referring to a static member of a subclass

开发者 https://www.devze.com 2023-02-07 11:47 出处:网络
I wish 开发者_开发知识库there was a sub keyword that would make the code below print value on execution. There isn\'t though and I wonder -is there an existing way to refer to a member of a subclass?

I wish 开发者_开发知识库there was a sub keyword that would make the code below print value on execution. There isn't though and I wonder - 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();


I think you are looking for static::$variable. That's called Late Static Binding and is available as of PHP 5.3.

0

精彩评论

暂无评论...
验证码 换一张
取 消