Phius Phius - 2 years ago 264
PHP Question

Laravel breaks entire app on PHP notices

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?

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.

Answer Source

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'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.

You can see all the constants for error reporting here:

You can get more information on how to use error_reporting here:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download