🐛 Fix intermittent env loading failures#800
Merged
Merged
Conversation
Replace `USE_ENV_ARRAY` with `LOCAL_FIRST` in `Env\Env::$options` so env lookups use `getenv()` instead of the unreliable `$_ENV` superglobal. Also replace magic number `31` with explicit bit flags. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This was referenced Mar 8, 2026
retlehs
added a commit
that referenced
this pull request
Mar 8, 2026
Stale formatting from #800. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
retlehs
added a commit
that referenced
this pull request
Mar 8, 2026
* ✅ Add Pest testing scaffold * 🎨 Format application.php Stale formatting from #800. --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
xelmido
pushed a commit
to xelmedia/bedrock-headless-zilch
that referenced
this pull request
Apr 1, 2026
Replace `USE_ENV_ARRAY` with `LOCAL_FIRST` in `Env\Env::$options` so env lookups use `getenv()` instead of the unreliable `$_ENV` superglobal. Also replace magic number `31` with explicit bit flags. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
xelmido
pushed a commit
to xelmedia/bedrock-headless-zilch
that referenced
this pull request
Apr 1, 2026
* ✅ Add Pest testing scaffold * 🎨 Format application.php Stale formatting from roots#800. --------- 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
USE_ENV_ARRAYwithLOCAL_FIRSTinEnv\Env::$options31) with explicit bit flags for readability and intentFixes #756
Problem
USE_ENV_ARRAYforcesoscarotero/envto read from$_ENVonly. In #756, multiple users reported intermittent misses in some contexts (notably WP-CLI and sequential command flows), whereenv()returnsnullfor expected values (e.g.DB_HOST), leading to fallback behavior likelocalhostand database connection failures.Fix
Set
Env\Env::$optionsexplicitly toCONVERT_BOOL | CONVERT_NULL | CONVERT_INT | STRIP_QUOTES | LOCAL_FIRST.This changes lookup to
getenv()(local first), which aligns with Bedrock's dotenv repository setup that includesPutenvAdapter, while still avoiding$_SERVER(the security goal of #598).Test results
Tested on a Trellis VM running Bedrock with this change applied:
Basic env loading:
Nested WP-CLI commands (the reported #756 failure case):
wp rewrite structure(triggers internalrewrite flush, another reported failure):Repeated read consistency:
$_SERVER not leaking .env secrets (#598 security intent preserved):
🤖 Generated with Claude Code