php命名空間與自動加載函數一起使用

命名空間下Config.php
namespace Auth\Config;
final class Config{
const AK=”adhsjskndhjasha”;
const SK=”ahdjkshaksjahdk”;
}

文件自動加載函數;

{
    $path = str_replace('\\', DIRECTORY_SEPARATOR, $class);
    $file = __DIR__ . '/Auth/' . $path . '.php';

    if (file_exists($file)) {
        require_once $file;
    }
}
spl_autoload_register("classLoader");
use Auth\Config;
echo Config::AK;
這裏寫代碼片
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章