Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Values of variables that depend on APP_ENV change according to its position #32595

Closed
@MGatou

Description

@MGatou

Description
In my .env file, I have a variable TEST that depends on the APP_ENV variable like this:

# .env file

###> symfony/framework-bundle ###
APP_ENV=dev
APP_SECRET=2eb810c79fba0dd5c029a2fa53bfdb51
###< symfony/framework-bundle ###

TEST=foo_${APP_ENV}

I run composer dump-env dev command to generate my .env.locale.php, everything works fine, the value of my variable TEST is correct.

// .env.locale.php

return array (
  'APP_ENV' => 'dev',
  'TEST' => 'foo_dev',
  'APP_SECRET' => '2eb810c79fba0dd5c029a2fa53bfdb51',
);

Then I run the same command with prod environment (composer dump-env prod), the value of TEST is wrong (it is same as for dev)

// .env.locale.php

return array (
  'APP_ENV' => 'prod',
  'TEST' => 'foo_dev',
  'APP_SECRET' => '2eb810c79fba0dd5c029a2fa53bfdb51',
);

But when I put my variable TEST before the APP_ENV like this:

# .env file

TEST=foo_${APP_ENV}

###> symfony/framework-bundle ###
APP_ENV=dev
APP_SECRET=2eb810c79fba0dd5c029a2fa53bfdb51
###< symfony/framework-bundle ###

And I run composer dump-env prod again, the value of TEST is correct

// .env.locale.php

return array (
  'APP_ENV' => 'prod',
  'TEST' => 'foo_prod',
  'APP_SECRET' => '2eb810c79fba0dd5c029a2fa53bfdb51',
);

How can we explain that ?

How to reproduce

  • Create a new Symfony project composer create-project symfony/skeleton bug_app
  • Add new variable TEST in your .env
  • Run composer dump-env prod
  • Take a look at .env.locale.php
  • In your .env file, put your TEST variable before the APP_ENV
  • Then run composer dump-env prod again
  • Take a look at .env.locale.php again

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDotenvHelp wantedIssues and PRs which are looking for volunteers to complete them.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions