实现父类调用子类中重写静态成员

Original 2019-05-06 14:46:22 230
abstract:<?php class Father{     public static  $money = 52000;     public static  function getClass(){  &nbs
<?php

class Father{
    public static  $money = 52000;

    public static  function getClass(){
        return __CLASS__ ;
    }

    public static function getMoney(){
//        return self::getClass().'::'.self::$money;
        return static::getClass().'::'.static::$money;
    }

}

echo '类名 : '.Father::getClass()."<hr>";
echo '方法 : '.Father::getMoney(),"<hr>";


class Son extends Father{
    public static  $money = 12000;

    public static  function getClass(){
        return __CLASS__ ;
    }
}
echo "<hr>";
echo Son::$money;
echo "<hr>";
echo Son::getClass();
echo "<hr>";
echo Son::getMoney();
?>


Correcting teacher:查无此人Correction time:2019-05-07 09:49:34
Teacher's summary:完成的不错。学习完类以后,就相当于php入门了。继续加油

Release Notes

Popular Entries