Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel breaks entire app on PHP notices

Tags:

php

laravel

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.

like image 566
Phius Avatar asked Aug 28 '13 20:08

Phius


People also ask

How do I hide warnings and notices in PHP?

In the current file, search for the line of code error_reporting. There will be a line of Default Value: E_ALL as shown below: Replace this line of code with Default Value: E_ALL & ~E_NOTICE. It will display all the errors except for the notices.

How do I enable error reporting in laravel?

Through your config/app. php , set 'debug' => env('APP_DEBUG', false), to true . Or in a better way, check out your . env file and make sure to set the debug element to true.


2 Answers

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

like image 106
Alright Avatar answered Oct 08 '22 08:10

Alright


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

like image 21
must Avatar answered Oct 08 '22 08:10

must