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

Skip to content

[Dotenv][WebServerBundle] Possible BC break when overriding previously loaded variables #24078

Closed
@javiereguiluz

Description

@javiereguiluz
Q A
Bug report? yes
Feature request? no
BC Break report? yes
RFC? no
Symfony version 3.3

As reported by @tiger-seo in #23799:


  1. i am grateful for all your hard work, but this change is a breaking change and it is not mentioned :(

  2. to give you more info why it is a BC, please see our env_autoload.php, which is used instead of autoload.php:

<?php

/** @var \Composer\Autoload\ClassLoader $loader */

use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\Dotenv\Exception\PathException;

$loader = require __DIR__ . '/autoload.php';

$dotenv = new Dotenv;

try {
    // existing environment variables are never overridden
    $dotenv->load(__DIR__ . '/config/.env');
} catch (PathException $e) {
}

// existing environment variables are never overridden
$dotenv->load(__DIR__ . '/config/.env.dist');

return $loader;
  1. @tiger-seo, I think you could try to load the .env.dist earlier than the .env:
// existing environment variables are never overridden
$dotenv->load(__DIR__ . '/config/.env.dist');

try {
    // existing environment variables are never overridden
    $dotenv->load(__DIR__ . '/config/.env');
} catch (PathException $e) {
}

return $loader;
  1. yes, this is exactly how we've fixed it

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions