PHP:是否可以检索子类的类名?

And*_*rew 1 php oop

class Bob extends Person
{
    //do some stuff
}

class Person
{
    public function __construct()
    {
        //get the class name of the class that is extending this one
        //should be Bob
    }
}
Run Code Online (Sandbox Code Playgroud)

如何Bob从类的构造函数中获取类名Person

Sav*_*man 7

使用get_class($ this).

它适用于子类,子子类,父类,一切.就试一试吧!;)