php 手册学习 ----- get_called_class 和 get_class

get_class (): 获取当前调用方法的类名; 
get_called_class():获取静态绑定后的类名;

abstract class dbObject
{    
    const TABLE_NAME='undefined';
    
    public static function GetAll()
    {
        $c = get_called_class();
        return "SELECT * FROM `".$c::TABLE_NAME."`";
    }    
}

class dbPerson extends dbObject
{
    const TABLE_NAME='persons';
}

class dbAdmin extends dbPerson
{
    const TABLE_NAME='admins';
}

echo dbPerson::GetAll()."<br>";//output: "SELECT * FROM `persons`"
echo dbAdmin::GetAll()."<br>";//output: "SELECT * FROM `admins`"

 

posted @ 2019-07-01 11:23  没事就更  阅读(212)  评论(0编辑  收藏  举报