@@ -145,18 +145,16 @@ public function getEnv(string $prefix, string $name, \Closure $getEnv): mixed
145
145
146
146
if (false !== $ i || 'string ' !== $ prefix ) {
147
147
$ env = $ getEnv ($ name );
148
- } elseif (isset ($ _ENV [$ name ])) {
149
- $ env = $ _ENV [$ name ];
150
- } elseif (isset ($ _SERVER [$ name ]) && !str_starts_with ($ name , 'HTTP_ ' )) {
151
- $ env = $ _SERVER [$ name ];
152
- } elseif (false === ($ env = getenv ($ name )) || null === $ env ) { // null is a possible value because of thread safety issues
148
+ } elseif ('' === ($ env = $ _ENV [$ name ] ?? (str_starts_with ($ name , 'HTTP_ ' ) ? null : ($ _SERVER [$ name ] ?? null )))
149
+ || false === ($ env = $ env ?? getenv ($ name ) ?? false ) // null is a possible value because of thread safety issues
150
+ ) {
153
151
foreach ($ this ->loadedVars as $ vars ) {
154
- if (false !== $ env = ($ vars [$ name ] ?? false )) {
152
+ if (false !== ( $ env = ($ vars [$ name ] ?? false )) && '' !== $ env ) {
155
153
break ;
156
154
}
157
155
}
158
156
159
- if (false === $ env || null === $ env ) {
157
+ if (false === $ env || '' === $ env ) {
160
158
$ loaders = $ this ->loaders ;
161
159
$ this ->loaders = new \ArrayIterator ();
162
160
@@ -169,7 +167,7 @@ public function getEnv(string $prefix, string $name, \Closure $getEnv): mixed
169
167
continue ;
170
168
}
171
169
$ this ->loadedVars [] = $ vars = $ loader ->loadEnvVars ();
172
- if (false !== $ env = $ vars [$ name ] ?? false ) {
170
+ if (false !== ( $ env = ( $ vars [$ name ] ?? false )) && '' !== $ env ) {
173
171
$ ended = false ;
174
172
break ;
175
173
}
@@ -184,7 +182,7 @@ public function getEnv(string $prefix, string $name, \Closure $getEnv): mixed
184
182
}
185
183
}
186
184
187
- if (false === $ env || null === $ env ) {
185
+ if (false === $ env ) {
188
186
if (!$ this ->container ->hasParameter ("env( $ name) " )) {
189
187
throw new EnvNotFoundException (sprintf ('Environment variable not found: "%s". ' , $ name ));
190
188
}
@@ -218,7 +216,7 @@ public function getEnv(string $prefix, string $name, \Closure $getEnv): mixed
218
216
if (\in_array ($ prefix , ['bool ' , 'not ' ], true )) {
219
217
$ env = (bool ) (filter_var ($ env , \FILTER_VALIDATE_BOOL ) ?: filter_var ($ env , \FILTER_VALIDATE_INT ) ?: filter_var ($ env , \FILTER_VALIDATE_FLOAT ));
220
218
221
- return 'not ' === $ prefix ? ! $ env : $ env ;
219
+ return 'not ' === $ prefix xor $ env ;
222
220
}
223
221
224
222
if ('int ' === $ prefix ) {
0 commit comments