Laravel在PHP公告上打破了整个应用程序 [英] Laravel breaks entire app on PHP notices

查看:46
本文介绍了Laravel在PHP公告上打破了整个应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使Laravel 4或5忽略PHP通知(如未定义的变量通知),而不仅仅因为简单的未定义的索引或变量" PHP通知就破坏整个应用程序?

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 3上在config/error.php中设置一个'ignore'数组.但是我找不到在Laravel 4或5中怎么做的.

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.

推荐答案

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

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.php if you're using Laravel 4, or line 29 in vendor/laravel/framework/src/illuminate/Foundation/Bootstrap/HandleExceptions.php if you're using Laravel 5:

error_reporting(-1); // Reports everything

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

Laravel's error handler respects your error_reporting level, 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)

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.

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

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

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

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

这篇关于Laravel在PHP公告上打破了整个应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆