为了账号安全,请及时绑定邮箱和手机立即绑定

spl_autoload_register与throw new Exception相冲突

spl_autoload_register与throw new Exception相冲突

PHP
慕桂英546537 2019-03-15 12:44:11
我自己搭建了一个自动引入文件的架构 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 5Fatal 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 这个错误
查看完整描述

3 回答

?
12345678_0001

TA贡献1802条经验 获得超5个赞

throw new \Exception("error");

尝试一下
查看完整回答
反对 回复 2019-03-18
?
慕虎7371278

TA贡献1802条经验 获得超4个赞

当你使用spl_autoload_register函数注册自动载入后还需要使用spl_autoload_call 或者spl_autoload来调用你需要的类。

查看完整回答
反对 回复 2019-03-18
  • 3 回答
  • 0 关注
  • 391 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信