Laravel 5 Error Reporting Suppression

2019-02-16 14:09发布

问题:

In Laravel 4, it was easy enough to suppress E_NOTICE messages; I can't seem to be able to do this because if I add

error_reporting(E_ALL ^ E_NOTICE) 

anywhere it simply gets overridden.

This seems to happen around here: (index.php)

$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()

);

I have added custom code to handle more "pretty" views of exceptions/errors within Exceptions/Handler.php but I'm struggling to switch off notices (I don't want any of these firing off with notices at all)

  • Yes, the issue should be fixed, I'm aware of this, however this is a case where I'd prefer the notices NOT bombing the app on live (I have a custom logging solution for this), and on dev I'd like the notice to show.

回答1:

In Laravel 5, we can set error_reporting(E_ALL ^ E_NOTICE) inside the AppServiceProviders::boot method:

public function boot()
{
    //set whatever level you want
    error_reporting(E_ALL ^ E_NOTICE);
} 


回答2:

Are you sure APP_DEBUG in your .env file is set to false in production? That might override your error_reporting() call.