Phius
Phius

Reputation: 724

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.

Upvotes: 14

Views: 14113

Answers (2)

Alright
Alright

Reputation: 131

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

Upvotes: 13

must
must

Reputation: 226

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: 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

Upvotes: 14

Related Questions