laravel / ideas

Issues board used for Laravel internals discussions.
938 stars 28 forks source link

env() should warn about cached config #1230

Open igorsantos07 opened 6 years ago

igorsantos07 commented 6 years ago

It's easy to overlook the mention about config caching on the documentation, and then start digging around on why your env() calls are weirdly empty in production, while the rest of the application seems to be working fine:

It's bad to have different behavior happening on the application that can only be explained by digging the docs, especially with something seldom-used as config/env vars - and that's not mentioned in the function description either.

My suggestion is to make env() issue a warning log explaining "you're probably doing something wrong".

drbyte commented 6 years ago

Yes it's easy to overlook clearing of the config cache.

However, when should env() "know" that something's "wrong", vs when values are expected to be empty or not defined at all?

staudenmeir commented 6 years ago

env() could throw an exception if it's called while the configuration is cached:

if (app()->configurationIsCached()) {
    throw new FooException('...');
}