开发者

Combine static var with parent's

This is what I'd like to be able to do:

class Test {
    public static $test = 'boo';
}

class Two extends Test {
    public static $test = parent::$test.'hoo';
}

// Two::$test开发者_如何学运维 == 'boohoo'

Well, specifically combining 2 arrays, but this illustrates it.

Is it possible?


This isn't possible because you can't evaluate anything when declaring a variable.

Something like:

class A {
    $seconds_in_a_day = 60*60*24; // invalid
    $seconds_in_a_day2 = 86400; // sour but valid
}

is invalid even.

You can move it to the constructor.

public function __construct() {
    self::$test = parent::$test.'hoo';
}

Aside from all that .. just don't do it. Save your future self a lot of work and find another more intuitive solution :P

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜