framework icon indicating copy to clipboard operation
framework copied to clipboard

All error are converted to ErrorException

Open ibrasho opened this issue 11 years ago • 2 comments

I've been trying to use the OptionsResolver component in Symfony, and since 2.6 the OptionsResolverInterface executed a trigger_error() to note that this interface is deprecated.

This is converted to an ErrorException in Laravel regardless of the E_USER_DEPRECATED level.

I can change this functionality by overriding the Handler, but can we change the default behaviour for the following errors, to log the error instead of halting the application?

  • E_NOTICE
  • E_WARNING
  • E_DEPRECATED
  • E_USER_NOTICE
  • E_USER_WARNING
  • E_USER_DEPRECATED

ibrasho avatar Dec 11 '14 10:12 ibrasho

Laravel by default sets error_reporting to -1, to enable all errors. In Illuminate\Exception\Handler::handleError there is a check error_reporting() & $level which is then always true, however by setting a less strict reporting level yourself you can ignore certain errors.

JoostK avatar Dec 11 '14 20:12 JoostK

Hi, I verified your statement however by setting a less strict reporting level yourself you can ignore certain errors. but I think you cannot change error_reporting to a less strict reporting level, in fact error_reporting is overwritten with -1 and never restored

We have a situation where we want ignore some errors but we can't because of that line of code !

Our solution was to patch bootstrap/app.php and save in container['php.error_reporting_startup'] the previous error_reporting value cominig from web server or system wide php settings, after that we restore error_reporting in a service provider after the kernel boot


// \Illuminate\Foundation\Bootstrap\HandleExceptions class

 public function bootstrap(Application $app)
    {
        $this->app = $app;
        error_reporting(-1);
        set_error_handler([$this, 'handleError']);
        set_exception_handler([$this, 'handleException']);
        register_shutdown_function([$this, 'handleShutdown']);
        if (! $app->environment('testing')) {
            ini_set('display_errors', 'Off');
        }
    }

We suffered a lot investigating why laravel throwed every errors even when php error_reporting has been limited to a less strict level, I think this must finally documented in the doc !

see also this stackoverflow thread

MatteoOreficeIT avatar Feb 20 '19 15:02 MatteoOreficeIT