How to get the path of a derived class from an inherited method?

前端 未结 6 1831
轮回少年
轮回少年 2021-01-30 13:11

How to get the path of the current class, from an inherited method?

I have the following:



        
6条回答
  •  庸人自扰
    2021-01-30 13:38

    Using ReflectionClass::getFileName with this will get you the dirname the class Child is defined on.

    $reflector = new ReflectionClass("Child");
    $fn = $reflector->getFileName();
    return dirname($fn);
    

    You can get the class name of an object with get_class() :)

提交回复
热议问题