摘要:<?php //后期静态绑定,也叫延迟静态绑定 class Father { //静态属性 public static $money = 5000; //静态方法  
<?php
//后期静态绑定,也叫延迟静态绑定
class Father
{
//静态属性
public static $money = 5000;
//静态方法
public static function getClass()
{
//返回当前的类名
return __CLASS__;
}
//静态方法
public static function getMoney()
{
// return self::getClass().'=>'.self::$money;
//static 用在静态继承的上下文中,动态设置静态成员的调用者(主体)
return static::getClass().'=>'.static::$money;
}
}
//定义子类,继承自Father
class Son extends Father
{
//覆写静态属性
public static $money = 3000;
//覆写静态方法
public static function getClass()
{
//返回当前的类名
return __CLASS__;
}
}
//调用Father中的静态方法,来获取类名
echo Father::getClass(),'<br>';
echo Father::getMoney(),'<br>';
//调用子类Son中的静态成员
echo Son::$money,'<br>';
echo Son::getClass(),'<br>';
echo '<hr>';
//子类中调用父类中的getMoney
echo Son::getMoney(),'<br>';后期静态绑定技术主要是通过在父类的方法中使用static而不是self来实现,如果父类有子类的话,会自动调用子类中的静态属性和静态方法来覆写父类中的静态属性和静态方法

批改老师:查无此人批改时间:2019-03-25 09:18:11
老师总结:完成的不错。类是最常用的,所以要牢记。继续加油