后期静态绑定

Original 2019-07-04 15:53:15 140
abstract:后期静态技术绑定,动态匹配成员的调用者<?php class Big {     public static $product = '海尔';     public static function getClass(

后期静态技术绑定,动态匹配成员的调用者

<?php

class Big
{
    public static $product = '海尔';
    public static function getClass()
    {
        return __CLASS__;
    }
    public static function getPro()
    {
//        return '一级分类:' .self::getClass() .'<br>品牌:' .self::$product;
        return '一级分类:' .static::getClass() .'<br>品牌:' .static::$product;
    }
}

class Small extends Big
{
    public static $product = '格力';
    public static function getClass()
    {
        return __CLASS__;
    }
}


echo Big::$product .'<hr>';

echo Big::getClass() .'<hr>';

echo Big::getPro() .'<hr>';

echo Small::$product .'<hr>';

echo Small::getClass() .'<hr>';

echo Small::getPro() .'<br>';


Correcting teacher:天蓬老师Correction time:2019-07-05 14:40:52
Teacher's summary:其实现在在很多场景下, 类中的需要用到self::的地方, 其实都是可以用static::来替代的, 这样通用性更强一些

Release Notes

Popular Entries