The package exposes one worker class (Repository), a static facade over a
shared instance of it (DotENV), and one global helper (env()).
InitPHP\DotENV\Repository
public function create(string $path, bool $debug = true): voidReads and defines a .env or .env.php file.
$path— a path to a.env/.env.phpfile, or to a directory that contains one. When a directory is given,.envis tried first, then.env.php.$debug— whentrue(default), problems throw aDotENVException; whenfalse, problems are ignored and the method returns without defining anything.
Values already present in $_ENV or $_SERVER are not overwritten.
public function get(string $name, mixed $default = null): mixedReturns an environment value, looked up as $_ENV → $_SERVER → getenv().
Strings are coerced (value types) and ${VAR} references
are interpolated (interpolation). Returns
$default when the name is not defined anywhere.
public function env(string $name, mixed $default = null): mixedAlias of get().
public function flush(): voidRemoves every value this repository defined (from $_ENV, $_SERVER and
putenv()) and clears the read cache. Pre-existing environment variables are
left untouched.
InitPHP\DotENV\DotENV
A static facade that forwards create(), get(), env() and flush() to a
single shared Repository. It adds two lifecycle helpers:
public static function instance(): RepositoryReturns the shared repository, creating it on first use.
public static function reset(): voidFlushes the shared repository and discards it, so the next call builds a fresh one. Useful in tests and long-running workers.
use InitPHP\DotENV\DotENV;
DotENV::create(__DIR__);
DotENV::get('APP_ENV');
DotENV::flush(); // unload, keep the instance
DotENV::reset(); // unload and drop the instanceRegistered through Composer's files autoloader:
function env(string $name, mixed $default = null): mixedEquivalent to DotENV::get($name, $default) and shares the same shared
repository. It is only defined if no other env() function already exists.
$appEnv = env('APP_ENV', 'production');Before 3.0 the worker class was named InitPHP\DotENV\Lib. That name still
resolves — it is registered as an alias of Repository — but it is
deprecated. Use Repository in new code.