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

Original 2019-04-15 19:52:18 200
abstract:<?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();


Correcting teacher:查无此人Correction time:2019-04-16 09:39:00
Teacher's summary:完成的不错。学完php的类,已经算入门了。要坚持,继续加油。

Release Notes

Popular Entries