Test whether a file exists anywhere in the include path

后端 未结 5 2245
时光取名叫无心
时光取名叫无心 2021-02-20 12:25

I\'m writing an autoload function and in the inner logic of it would like to test whether a certain file exists somewhere in the path prior to including it.

This is the

5条回答
  •  难免孤独
    2021-02-20 12:54

    I would use file_exists rather than a warnings-suppressed include.

    Then you'll have to iterate through the include_path:

    $paths = explode(';', get_include_path());
    foreach($paths as $p){
        if(file_exists($p . '/' . $calculatedPath)){
            include $p . '/' . $calculatedPath;
            break;
        }
    }
    

提交回复
热议问题