fix(env): write the assignment a PHP settings file actually runs - #1400
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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:
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