Get class name from file

后端 未结 10 1834
轮回少年
轮回少年 2020-12-08 10:29

I have a php file which contains only one class. how can I know what class is there by knowing the filename? I know I can do something with regexp matching but is there a st

10条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-08 11:19

    You may be able to use the autoload function.

    function __autoload($class_name) {
        include "special_directory/" .$class_name . '.php';
    }
    

    And you can echo $class_name. But that requires a directory with a single file.

    But it is standard practice to have one class in each file in PHP. So Main.class.php will contain Main class. You may able to use that standard if you are the one coding.

提交回复
热议问题