🩹 Skip env file loading when no .env file exists#500
Merged
retlehs merged 2 commits intoMar 9, 2026
Conversation
QWp6t
requested changes
Feb 25, 2026
QWp6t
left a comment
Member
There was a problem hiding this comment.
Thanks for the PR, but unfortunately this won't be merged in its current state because it updates a vendored Illuminate file. Nothing within src/Illuminate/ should be modified.
Contributor
Author
|
Thank you for the quick reply, I'll look for another option. And come back with an updated version. |
ace303d to
22c2b23
Compare
When no .env file exists anywhere in the directory tree, Application::environmentPath() falls back to basePath(). phpdotenv then calls @file_get_contents() on the non-existent file, which emits a suppressed PHP warning. Error tracking tools like Sentry still capture these suppressed warnings, generating noise. This adds a Roots\Acorn\Bootstrap\LoadEnvironmentVariables bootstrapper that checks if the environment file exists before attempting to load it. If the file doesn't exist, loading is skipped entirely since environment variables are provided by other means (server config, Docker, etc.). Fixes #496
22c2b23 to
2f675e9
Compare
Tests cover: - missing .env file skips dotenv load (no warning) - existing .env file loads normally - cached configuration skips loading entirely Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
Fixes #496
When no
.envfile exists anywhere in the directory tree,Application::environmentPath()falls back tobasePath(). phpdotenv'sReader::readFromFile()then calls@file_get_contents()on the non-existent<basePath>/.env, emitting a suppressed PHP warning. Error tracking tools like Sentry still capture these suppressed warnings, generating noise on every request.Approach
This adds a
Roots\Acorn\Bootstrap\LoadEnvironmentVariablesbootstrapper — following the existing pattern used byLoadConfiguration,HandleExceptions, andRegisterFacades— that checks if the environment file exists before attempting to load it. If the file doesn't exist, loading is skipped entirely since environment variables are provided by other means (server config, Docker, GKE, etc.).Both
Http\KernelandConsole\Kernelare updated to use the new Acorn bootstrapper.Changes
src/Roots/Acorn/Bootstrap/LoadEnvironmentVariables.php— extendsIlluminate\Foundation\Bootstrap\LoadEnvironmentVariableswith anis_file()guardsrc/Roots/Acorn/Http/Kernel.php— useRoots\Acorn\Bootstrap\LoadEnvironmentVariablessrc/Roots/Acorn/Console/Kernel.php— useRoots\Acorn\Bootstrap\LoadEnvironmentVariablesNo vendored
src/Illuminate/files are modified.