Search code examples
symfonysymfony5

Can I enable exceptions on warnings in production?


Just like in debug mode, I'd like Symfony to catch any notice or warning in my prod environment, and convert it to an exception.

Can I do this without enabling the whole debug mode?

Take the following code for example, that generates a PHP warning:

$x = null;
dump($x['foo']);

With APP_DEBUG=1, the warning is converted to an exception:

ErrorException: Warning: Trying to access array offset on null

Whereas with APP_DEBUG=0, the warning is silently discarded:

^ null

I'd like Symfony to convert the warning to an exception even when APP_DEBUG=0.


Solution

  • https://symfony.com/doc/current/reference/configuration/framework.html#php-errors

    config/packages/framework.yaml

    framework:
        ....
        php_errors:
            throw: true