Skip to content

fix(env): write the assignment a PHP settings file actually runs - #1400

Merged
geodro merged 2 commits into
mainfrom
fix/php-vars-writes-the-winning-assignment
Aug 8, 2026
Merged

fix(env): write the assignment a PHP settings file actually runs#1400
geodro merged 2 commits into
mainfrom
fix/php-vars-writes-the-winning-assignment

Conversation

@geodro

@geodro geodro commented Aug 8, 2026

Copy link
Copy Markdown
Member

Writing a PHP settings file updated the first statement that reached a key. PHP runs a file top to bottom, so where a later statement reaches the same key the value lerd wrote was shadowed by whatever came after it:

$databases['default']['default'] = ['host' => 'lerd-mysql'];   <- lerd wrote here
$databases['default']['default'] = ['host' => 'other'];        <- the site uses this

The file says one thing and the application uses another, which is worse than either, because every surface then reports a database the site is not on. The ordinary shape of a settings file makes it easy to hit, since a local override at the end is exactly a later statement reaching the same key.

The owning statement is the last one to reach the key now, whether that is a whole array replacing an earlier one or a leaf overriding it, and a statement assigning the key itself has its value replaced rather than being descended into. Reading already applied assignments in file order the way PHP would run them, so the two agree again.

Everything else the file says is left alone. A port set in an array and a host overridden by a later leaf both land in the statement that owns them:

$databases['default']['default'] = [
    'host' => 'old',
    'port' => 3307,
];
$databases['default']['default']['host'] = 'lerd-mysql';

which reads back as host lerd-mysql and port 3307, the values PHP would see.

The other formats were checked and are unaffected: a dotenv writer rewrites every occurrence of a key, so no contradiction survives it, and a php-const writer updates the first define, which is the one PHP keeps.

Closes #1399

Writing updated the first statement that reached a key. PHP runs a file top to bottom, so where a later statement reaches the same key the value lerd wrote was shadowed by whatever came after it: the file said one thing and the application used another, which is worse than either, because every surface then reports a database the site is not on. The ordinary shape of a settings file makes this easy to hit, since a local override at the end is exactly a later statement reaching the same key.

The owning statement is the last one to reach the key now, whether that is a whole array replacing an earlier one or a leaf overriding it, and a statement assigning the key itself has its value replaced rather than being descended into. Reading already applied assignments in file order the way PHP would run them, so the two agree again.

Everything else the file says is left alone: a key no later statement touches is still written where it lives, so a port set in an array and a host overridden below it both land in the statement that owns them.
@geodro
geodro requested a review from a team as a code owner August 8, 2026 06:51
@geodro
geodro merged commit 7a04b36 into main Aug 8, 2026
3 checks passed
@geodro
geodro deleted the fix/php-vars-writes-the-winning-assignment branch August 8, 2026 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(env): writing a PHP settings file updates a statement a later one overrides

1 participant