Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

symfony - usePutenv default change deprecation warning fix

After upgrading symfony to 4.3, when running the unit tests I get the following warning:

Other deprecation notices (1)

  1x: The default value of "$usePutenv" argument of "Symfony\Component\Dotenv\Dotenv::__construct" will be changed from "true" to "false" in Symfony 5.0. You should define its value explicitly.
    1x in Dotenv::__construct from Symfony\Component\Dotenv

The warning itself is rather clear and the fix should be clear but... I find no config to explicitly define that value (I would actually love to read its current value first just to double check). Any idea how to fix this (where to define it)?

P.S. I know that it doesn't interfere with anything right now but I see no reason not to have a clean output and code with no "hidden surprises".

Edit: From what I see the call to Dotenv is hardcoded directly in bootstrap here:

(new Dotenv())->loadEnv(dirname(__DIR__).'/.env');

Should I modify it there or is there a better way?

like image 923
zozo Avatar asked Dec 11 '22 01:12

zozo


1 Answers

If installing a new Symfony 4.4(-dev) the line in config/bootstrap.php will be:

//old
(new Dotenv())->loadEnv(dirname(__DIR__).'/.env');

//new
(new Dotenv(false))->loadEnv(dirname(__DIR__).'/.env');

Just put the false in to clear the message and continue as you already are - and be explicit and compatible with Symfony 5.0, unless you need the know that you are using a result of $usePutenv = true. (unlikely, as it is defaulting otherwise).

like image 114
Alister Bulman Avatar answered Dec 27 '22 11:12

Alister Bulman