简体   繁体   English

在Laravel中对严重错误禁用exit()

[英]Disable exit() on strict errors in Laravel

I have a Laravel application that has to integrate with a legacy external code base. 我有一个Laravel应用程序,必须与旧版外部代码库集成。 I spent weeks making sure that everything worked. 我花了数周的时间来确保一切正常。 Unfortunately I'm not the only developer, and as the other code base doesn't exit on strict errors, they don't get fixed, or caught, until it breaks my code. 不幸的是,我不是唯一的开发人员,并且由于其他代码库不会因严格的错误而退出,因此它们不会被固定或捕获,直到它破坏了我的代码。 And I only find out afterwards. 然后我才发现。

I need to disable exit() on strict errors. 我需要在出现严重错误时禁用exit()。 Fatal errors should still fail. 致命错误仍然应该失败。 A cursory google search only returns "Don't" which is obviously the best option, but unfortunately not possible in my circumstances. 粗略的Google搜索只会返回“不”,这显然是最好的选择,但不幸的是在我的情况下是不可能的。

Add error_reporting line right after application initialization to bootstrap/app.php as follow: 在应用程序初始化后立即将error_reporting行添加到bootstrap/app.php ,如下所示:

$app = new Illuminate\Foundation\Application(
    // Laravel\Lumen\Application in case of Lumen
    realpath(__DIR__.'/../')
);
error_reporting(E_ALL & ~E_STRICT);

This will prevent ErrorException to be thrown on E_STRICT . 这样可以防止将ErrorException抛出在E_STRICT Same applies for Lumen : 同样适用于流明

$app = new Laravel\Lumen\Application(
    realpath(__DIR__.'/../')
);
error_reporting(E_ALL & ~E_STRICT);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM