class employee{
public static $sport = "football";
public static function watchTV(){
echo 'watching '.self::$sport;
}
}
class CEO extends employee{
public static $sport = "basketball";
}
echo CEO::watchTV(); //watching football
//这个结构是watching football,不是watching basketball。因为self会在编译是确定其作用域而不是在运行时。
//php5.3以后:
class employee{
public static $sport = "football";
public static function watchTV(){
echo 'watching '.static::$sport; //
}
}
class CEO extends employee{
public static $sport = "basketball";
}
echo CEO::watchTV(); //watching basketball
php--继承与延迟静态绑定
最新推荐文章于 2021-07-20 23:16:15 发布