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

spl_autoload_register與throw new Exception相沖突

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

spl_autoload_register自動(dòng)載入文件
但是我在控制器中使用throw new Exception的時(shí)候報(bào)了錯(cuò)誤

**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**

也就是說(shuō)spl_autoload_register把exception也一起給自動(dòng)載入了
有什么辦法可以解決這個(gè)嗎?


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

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

但是還是報(bào)
Uncaught Error: Class 'RestException' not found 這個(gè)錯(cuò)誤

回答
編輯回答
莫小染

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

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

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

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

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