搜索

利用后期静态绑定技术,实现在父类调用子类中重写的静态成员

原创 2019-04-15 19:52:18 286
摘要:<?php //利用后期静态绑定技术,实现在父类调用子类中重写的静态成员 //创建父类 class Father {     public static $price=5000;     public static function getClass()
<?php
//利用后期静态绑定技术,实现在父类调用子类中重写的静态成员
//创建父类
class Father
{
    public static $price=5000;
    public static function getClass()
    {
        return __CLASS__;
    }
    public static function getPrice()
    {
        return static::getClass().':'.static::$price;
    }
}
//创建子类
class Son extends Father
{
    public static $price=8000;
    public static function getClass()
    {
        return __CLASS__;
    }
}
echo Father::$price,'<br>';
echo Father::getClass(),'<br>';

echo Son::$price,'<br>';
echo Son::getClass(),'<br>';

echo Son::getPrice();


批改老师:查无此人批改时间:2019-04-16 09:39:00
老师总结:完成的不错。学完php的类,已经算入门了。要坚持,继续加油。

发布手记

热门词条