摘要:后期靜態(tài)技術(shù)綁定,動(dòng)態(tài)匹配成員的調(diào)用者<?php class Big { public static $product = '海爾'; public static function getClass(
后期靜態(tài)技術(shù)綁定,動(dòng)態(tài)匹配成員的調(diào)用者
<?php class Big { public static $product = '海爾'; public static function getClass() { return __CLASS__; } public static function getPro() { // return '一級(jí)分類:' .self::getClass() .'<br>品牌:' .self::$product; return '一級(jí)分類:' .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>';
批改老師:天蓬老師批改時(shí)間:2019-07-05 14:40:52
老師總結(jié):其實(shí)現(xiàn)在在很多場(chǎng)景下, 類中的需要用到self::的地方, 其實(shí)都是可以用static::來(lái)替代的, 這樣通用性更強(qiáng)一些