Skip to content

fix: load .env before config cache to prevent null env values on startup#229

Merged
techmahedy merged 1 commit intodoppar:3.xfrom
techmahedy:techmahedy-3.x
Mar 14, 2026
Merged

fix: load .env before config cache to prevent null env values on startup#229
techmahedy merged 1 commit intodoppar:3.xfrom
techmahedy:techmahedy-3.x

Conversation

@techmahedy
Copy link
Member

Root cause

On application startup, Config::initialize() was called inside withConfiguration() before EnvServiceProvider had loaded the .env file. This meant every env() call inside config/*.php returned null. The resulting null-value config was then written to the cache file, and all subsequent requests served those stale null values — even after the process restarted and the .env was available.

A secondary issue:

The cache key was computed from the hashes of config/*.php files only. Changing .env did not invalidate the cache because the .env hash was not included in the key. The static memoisation on isCacheValid() also locked the result to false for the entire request lifetime, preventing recovery after the first miss.

@techmahedy techmahedy merged commit 75bd5a7 into doppar:3.x Mar 14, 2026
27 checks passed
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.

1 participant