Laravel 在 PHP 通知上破坏了整个应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18497788/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 08:20:38  来源:igfitidea点击:

Laravel breaks entire app on PHP notices

phplaravel

提问by Phius

How can I make Laravel 4 or 5 ignore PHP notices (like undefined variable notices) and not break the whole app only because of a simple 'undefined index or variable' PHP notice?

我怎样才能让 Laravel 4 或 5 忽略 PHP 通知(如未定义变量通知)并且不会因为简单的“未定义索引或变量”PHP 通知而破坏整个应用程序?

I could to that on Laravel 3 setting an 'ignore' array in config/error.php. But I cant find how to do that in Laravel 4 or 5.

我可以在 Laravel 3 上在 config/error.php 中设置一个“忽略”数组。但我无法在 Laravel 4 或 5 中找到如何做到这一点。

回答by must

This behavior is due to setting error reporting to -1. This is Laravel's default behaviour - see line 14 in vendor/laravel/framework/src/illuminate/Foundation/start.phpif you're using Laravel 4, or line 29 in vendor/laravel/framework/src/illuminate/Foundation/Bootstrap/HandleExceptions.phpif you're using Laravel 5:

此行为是由于将错误报告设置为 -1。这是 Laravel 的默认行为 -vendor/laravel/framework/src/illuminate/Foundation/start.php如果您使用的是 Laravel 4,请参见第 14 行,如果您使用的是 Laravel 5,请参见第 29 行vendor/laravel/framework/src/illuminate/Foundation/Bootstrap/HandleExceptions.php

error_reporting(-1); // Reports everything

Laravel's error handler respects your error_reportinglevel, and will ignore any errors that you tell PHP not to report. It's worth mentioning that changing the error reporting level isn't a good idea. But to override the previous instruction you can add your error reporting preferences in the app/start/global.php(in Laravel 4) or app/bootstrap/app.php(in Laravel 5)

Laravel 的错误处理程序尊重您的error_reporting级别,并且会忽略您告诉 PHP 不要报告的任何错误。值得一提的是,更改错误报告级别并不是一个好主意。但是要覆盖之前的指令,您可以在app/start/global.php(在 Laravel 4 中)或app/bootstrap/app.php(在 Laravel 5 中)添加您的错误报告首选项

error_reporting(E_ALL ^ E_NOTICE); // Ignores notices and reports all other kinds

Again this isn't a solution. It's merely what you are asking for. All and any errors, warning, notices etc. can and should be fixed.

同样,这不是解决方案。这只是你所要求的。所有和任何错误、警告、通知等都可以而且应该被修复。

You can see all the constants for error reporting here: http://www.php.net/manual/en/errorfunc.constants.php

您可以在此处查看错误报告的所有常量:http: //www.php.net/manual/en/errorfunc.constants.php

You can get more information on how to use error_reporting here: http://php.net/manual/en/function.error-reporting.php

您可以在此处获取有关如何使用 error_reporting 的更多信息:http: //php.net/manual/en/function.error-reporting.php

回答by Alright

In Laravel 5.1 you can add error_reporting(0)or whatever you want into \app\Providers\AppServiceProvider.php boot() method

在 Laravel 5.1 中,您可以error_reporting(0)在 \app\Providers\AppServiceProvider.php boot() 方法中添加或添加任何您想要的内容