Symfony contains a great way to use environment variables in the service configuration. With the environment processor it's possible to supply bool variables the following way.
The related configuration in the .env can look like the this:
ARE_ALL_EXCEPTIONS_TRANSLATED=false
With bool:* this will be translated into the boolean false instead of the string "false" it's by default. Therefore within our service with can use bool as type:
As we're getting used to it, we must not forget, that this is custom logic by Symfony available through the environment processor and not default behaviour of PHP.
A bool cast with (bool) "false" results in true. Which means that we can't use APP_DEBUG=false in our .env with Symfony by default. Because Symfony has the following line in the console and the index.php:
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
This results in new Kernel('prod', true) when using APP_ENV=prod and APP_DEBUG=false. Only APP_DEBUG=0 would give us the desired result.
Alternatively we adapt the files with the logic borrowed from the environment processor from Symfony to have the same logic here. The interesting part is this:
With this, our adapted console and index.php will look like the following. You might need to adapt it if you have custom changes in your variants.