2012-02-01 82 views
2
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。 爲什麼?抽象靜態屬性不能被覆蓋?

回答

1

「自我」是由當前類使用, 如果你想獲得孩子的靜態屬性,用「靜」爲:

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