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

前端 未结 6 1817
轮回少年
轮回少年 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:45

    Don't forget, since 5.5 you can use class keyword for the class name resolution, which would be a lot faster than calling get_class($this). The accepted solution would look like this:

    protected function getDir() {
        return dirname((new ReflectionClass(static::class))->getFileName());
    }
    

提交回复
热议问题