Skip to content

Commit 88203b1

Browse files
[DotEnv] Mention the overrideExistingVars parameter of DotEnv
1 parent a24e265 commit 88203b1

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

configuration.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,27 @@ the env files ending in ``.local`` (``.env.local`` and ``.env.<environment>.loca
872872
**should not be committed** because only you will use them. In fact, the
873873
``.gitignore`` file that comes with Symfony prevents them from being committed.
874874

875+
Overriding Environment Values Defined By The System
876+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
877+
878+
You may need to override an environment value defined by the system. This can
879+
be done thanks to the :class:`Symfony\\Component\\Dotenv\\Dotenv` class. The
880+
:method:`Symfony\\Component\\Dotenv\\Dotenv::loadEnv`,
881+
:method:`Symfony\\Component\\Dotenv\\Dotenv::bootEnv`, and
882+
:method:`Symfony\\Component\\Dotenv\\Dotenv::populate` methods accept an optional
883+
``overrideExistingVars`` parameter that allows you to override existing environment
884+
variables set by the system::
885+
886+
use Symfony\Component\Dotenv\Dotenv;
887+
888+
$dotenv = new Dotenv();
889+
$dotenv->loadEnv(__DIR__.'/.env', null, 'dev', ['test'], true);
890+
891+
// ...
892+
893+
This will override environment variables defined by the system
894+
and **won't** override environment variables defined in ``.env`` files.
895+
875896
.. _configuration-env-var-in-prod:
876897

877898
Configuring Environment Variables in Production

0 commit comments

Comments
 (0)