Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support .env.local config override (#594)
If `.env.local` exists, any values will override and take precedence over those in `.env`. This is meant for local development only.
- Loading branch information
b2781b8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get a PHP error, if the file
.env.local
doesn't exist.Maybe this could be handled by something like this?
b2781b8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's strange. phpdotenv just ignores files it can't read: https://github.com/vlucas/phpdotenv/blob/b740396414a95cbe868bf7f168f997fe16d970d6/src/Store/File/Reader.php#L33
Though you do need at least one working env file. Are you missing the main
.env
file? Without any, you'll seeFatal error: Uncaught Dotenv\Exception\InvalidPathException: Unable to read any of the environment file(s)
I just tried out a minimal test script and it worked as expected as well:
Worked with and without
.env.local
and overrode the values as expected.b2781b8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, my bad. It's not an error, it's just a warning.
Everything will work as it should, but anyway, I don't like warnings which I can avoid.
Thank you for getting into it, I really appreciate your support!
b2781b8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@swalkinshaw I found what cause the error.
Just a few lines in the file you linked, phpdotenv uses
file_get_contents
with error suppressor.https://github.com/vlucas/phpdotenv/blob/b740396414a95cbe868bf7f168f997fe16d970d6/src/Store/File/Reader.php#L73
If a file is not found,
file_get_contents
generates anE_WARNING
.After that, WordPress checks if there was any error in
admin-header.php
witherror_get_last
function that returns theE_WARNING
:https://github.com/WordPress/WordPress/blob/81f62198c388a0e0619d8dcb2f1e34b2f07e2bfb/wp-admin/admin-header.php#L199
A
.php-error
class is added to admin body that adds a margin under the admin bar and the user doesn't see any error because the output was suppressed.IMHO i would adopt a solution like that
I also removed
if (file_exists($root_dir . '/.env')) {
check because in my opinion if a configuration file is not provided a fatal error must be raised.