Skip to content

[Dotenv] Mention the overrideExistingVars parameter of DotEnv #19082

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,27 @@ the env files ending in ``.local`` (``.env.local`` and ``.env.<environment>.loca
**should not be committed** because only you will use them. In fact, the
``.gitignore`` file that comes with Symfony prevents them from being committed.

Overriding Environment Values Defined By The System
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

You may need to override an environment value defined by the system. This can
be done thanks to the :class:`Symfony\\Component\\Dotenv\\Dotenv` class. The
:method:`Symfony\\Component\\Dotenv\\Dotenv::loadEnv`,
:method:`Symfony\\Component\\Dotenv\\Dotenv::bootEnv`, and
:method:`Symfony\\Component\\Dotenv\\Dotenv::populate` methods accept an optional
``overrideExistingVars`` parameter that allows you to override existing environment
variables set by the system::

use Symfony\Component\Dotenv\Dotenv;

$dotenv = new Dotenv();
$dotenv->loadEnv(__DIR__.'/.env', null, 'dev', ['test'], true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use named arguments here and only add the required one + the overrideExistingVars parameter

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but 5.4 minimal req is PHP 7.2. Shouldn't the example be compatible with the lowest possible PHP version ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh indeed, but we can do it after upmerge

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll provide the PR 🙂


// ...

This will override environment variables defined by the system
and **won't** override environment variables defined in ``.env`` files.

.. _configuration-env-var-in-prod:

Configuring Environment Variables in Production
Expand Down