Skip to content

App::environment() ignores APP_ENV when --env option is used on cli #28854

@redelschaap

Description

@redelschaap
  • Laravel Version: 5.8.15
  • PHP Version: 7.3.4

Description:

The documentation says that "The current application environment is determined via the APP_ENV variable from your .env file.". It also says that "The current application environment detection can be overridden by a server-level APP_ENV environment variable."

However, when using artisan with the --env option, App::environment() will return the value of the --env option. To me as a developer, I find it logical that the --env option is used to determine the .env file to use, not to overrule the environment. After all, the name of the .env file can differ from the APP_ENV value in that file.

Steps To Reproduce:

  1. Copy the .env file to .env.foo;
  2. Change the value of APP_ENV within .env.foo to bar;
  3. Run php artisan tinker;
  4. Execute the command App::environment(), the value of APP_ENV should be returned;
  5. Quit Tinker and run php artisan tinker --env=foo;
  6. Execute the command App::environment();
  7. foo is now returned, instead of bar.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions