抽象静态属性不能被覆盖?

时间:2012-02-01 08:35:04

标签: php oop abstract-class

abstract class Ghost {

    protected static $var = 'I\'m a ghost';

    final public static function __callStatic($method, $args = array()) {
        echo self::$var;
    }

}


class Person extends Ghost { 
    protected static $var = 'I\'m a person';
}

Person::whatever()的来电将打印:I'm a ghost。 为什么呢?

2 个答案:

答案 0 :(得分:4)

您正在寻找名为Late Static Binding的内容,这需要PHP 5.3 +

答案 1 :(得分:1)

“自我”由Current类使用, 如果你想获得子静态属性,请使用“static”作为:

final public static function __callStatic($method, $args = array()) {
   echo **static**::$var;
}