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

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

    If you are using Composer for autoloading you can retrieve the directory without reflection.

    $autoloader = require 'project_root/vendor/autoload.php';
    // Use get_called_class() for PHP 5.3 and 5.4
    $file = $autoloader->findFile(static::class);
    $directory = dirname($file);
    

提交回复
热议问题