- Load
- Dotenv no longer autoload the
.envfile on creating a new instance by default. - To load the
.envfile on creating new instance, you now need to pass the second argument astruewhen instantiating the class. - You can now manually load the
.envfile by calling theload()method. load()method return Dotenv class.- Add new method
getInGroup(string $group),
- Dotenv no longer autoload the
// if you set your environment variables in group like this,
APP_URL='https://example.com/'
APP_KEY=1234567
// You can use `getInGroup` method to retrieve all of that same group variables,
$dotenv->getInGroup('APP');
// Output
array(2) {
[0] =>
string(7) "APP_URL"
[1] =>
string(7) "APP_KEY"
}- Remove deleted variables
- This includes removing deleted environment variables from
$_SERVER,$_ENV, andgetenv().
- This includes removing deleted environment variables from
- Remove env variables manually set process.
- Dotenv now accept 2 parameters,
array|string$file &string$path - Dotenv will load default defined
envfiles if user pass nothing to $file
// Change method name
// from
$dotenv->getInGroup('APP');
// to
$dotenv->group('APP');
// from
$dotenv->restart();
// to
$dotenv->reload(); // Reload no longer accept default values- replace
file()withfopen()for improved performance when reading env files - The constructor now accepts three parameters:
array|string|null$filestring|null$envKeybool$overwrite
- improved
loadmethod:- On production mode, env files are loaded only once (for performance)
- New method
has()to check for the existence of an env variable:
$dotenv->has('APP_LOCALE');- You can now control whether to overwrite existing environment variables when loading multiple env files, via the $overwrite parameter.
- JSON File Support β Load environment variables from structured
.jsonfiles. - Custom Loader Registry β Add support for user-defined loaders (e.g., YAML, XML).
- Static Access β Access env values directly using
Env::get()orEnv::group(). - Safe Loading β Use
safeLoad()to avoid exceptions on missing or malformed files. - Multiple File Support β Load multiple
.envand.jsonfiles in defined order. - Caching β Enable in-memory caching for performance using
cache: true. - LoaderRegistry β Convention-based class resolution for parsers like
JsonParser.
Env::create()no longer loads.envby default β use->load()explicitly.- Parser resolution now follows a naming convention (
JsonParser,YamlParser, etc.). - Parser must implement
ParserInterfaceand be registered for custom loaders.
- The legacy
$dotenv = new Dotenv(...)->load()style is replaced byEnv::create(...)->load(). - Parser resolution and loader registration are now required for custom file formats.
- Improved performance by using
fopen()instead offile()for reading files. - Cleaner architecture with
BaseLoader,LoaderInterface, andLoaderRegistry.