账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    spl_autoload_register与throw new Exception相冲突
    31
    0

    我自己搭建了一个自动引入文件的架构

    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 这个错误

    0
    打赏
    收藏
    点击回答
        全部回答
    • 共 0 条
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部