Skip to content

Commit

Permalink
Tweak some code.
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Feb 16, 2015
1 parent 7fa7594 commit 866a8cf
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/Foundation/Bootstrap/DetectEnvironment.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public function bootstrap(Application $app)
{
try
{
Dotenv::makeMutable();

Dotenv::load($app['path.base'], $app->environmentFile());

Dotenv::makeMutable();
}
catch (InvalidArgumentException $e)
{
Expand Down

4 comments on commit 866a8cf

@bioteck
Copy link
Contributor

Choose a reason for hiding this comment

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

It's very important that makeMutable() is called before load(). It's difficult to explain why, so I made scheme to clearly illustrate the problem:

schema01

But by calling makeMutable() first, load() can repopulate $_ENV, even if it's not empty. getenv() is still affected by the reset, but not $_ENV:

schema02

I remind that this bug only appears with thread-safe versions of PHP, and if two scripts are executed at the same time.

@taylorotwell
Copy link
Member Author

Choose a reason for hiding this comment

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

But we don't want it to override any existing ENV variables on load, because sometimes we set some in the web server or PHPUnit configuration.

@adamwathan
Copy link
Contributor

Choose a reason for hiding this comment

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

This change has caused a bug for me where when running my tests, the environment variables specified in phpunit.xml are only set for the first test. After that, my tests are using the environment variables listed in .env.

image

@bioteck
Copy link
Contributor

Choose a reason for hiding this comment

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

Erf... indeed, makeMutable() may be problematic... so we still have this problem with thread-safe versions of PHP. It's very annoying :(

Please sign in to comment.