Laravel breaks entire app on PHP notices

前端 未结 2 611
灰色年华
灰色年华 2020-12-14 21:18

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 n

相关标签:
2条回答
  • 2020-12-14 21:34

    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

    0 讨论(0)
  • 2020-12-14 21:36

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

    0 讨论(0)
提交回复
热议问题