在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/PHP  網(wǎng)絡(luò)安全  HTML/ spl_autoload_register與throw new Exceptio

spl_autoload_register與throw new Exception相沖突

我自己搭建了一個自動引入文件的架構(gòu)

spl_autoload_register自動載入文件
但是我在控制器中使用throw new Exception的時候報了錯誤

**Warning: require(/www/wwwroot/www.entercode.cn/api/Rest/Exception.php): failed to open stream: No such file or directory in /www/wwwroot/www.entercode.cn/api/Rest/Loader.php on line 5
Fatal error: require(): Failed opening required '/www/wwwroot/www.entercode.cn/api/Rest/Exception.php' (include_path='.:/www/server/php/70/lib/php') in /www/wwwroot/www.entercode.cn/api/Rest/Loader.php on line 5**

也就是說spl_autoload_register把exception也一起給自動載入了
有什么辦法可以解決這個嗎?


后面我在autoload做了一個判斷是否存,改成了

public static function autoload($class){
    $file=BASEDIR.'/'.str_replace('\\', '/', $class).'.php';
    if(file_exists($file)){
        require $file;
    }
} 

但是還是報
Uncaught Error: Class 'RestException' not found 這個錯誤

回答
編輯回答
莫小染

發(fā)你的 spl_autoload_register 注冊的函數(shù).

2018年3月6日 19:03
編輯回答
司令

當(dāng)你使用spl_autoload_register函數(shù)注冊自動載入后還需要使用spl_autoload_call 或者spl_autoload來調(diào)用你需要的類。

2017年3月13日 06:16
編輯回答
扯不斷
throw new \Exception("error");

嘗試一下
2017年7月29日 09:25