-
Notifications
You must be signed in to change notification settings - Fork 1
FAQ
Short answers to common questions. Most link to a fuller page.
No. create() never overwrites a name already defined in $_ENV,
$_SERVER, or getenv(). Real environment variables always win — see
Loading & Precedence.
Because coercing it to 7 would lose the leading zero. Numbers are coerced to
int/float only when the conversion round-trips exactly. See
Value Types & Coercion.
Cast at the call site:
$port = (int) DotENV::get('DB_PORT');
$enabled = filter_var(DotENV::get('FEATURE_X'), FILTER_VALIDATE_BOOL);Yes — use ${OTHER}. References are resolved on read, can appear multiple
times per line, and can nest. See
Variable Interpolation.
No. Only the ${VAR} form is recognised; a bare $VAR is left as literal
text.
A file must be named exactly .env or .env.php, so either keep
per-environment files in their own directories and point create() at the
directory, or layer an optional override file. See the patterns in
Recipes.
putenv() only accepts strings, so non-string values from a .env.php file
are stored in $_ENV / $_SERVER (and get() reads them) but are not pushed
to getenv(). Store it as a string if getenv() must see it. See
Using a PHP .env File.
Pass false as the second argument: DotENV::create($path, false) turns
every error (missing file, wrong type, unreadable) into a silent no-op. See
Error Handling.
Nothing functional — env() is a global helper equivalent to
DotENV::get(), sharing the same state. Use whichever reads better. See
API Reference.
DotENV is a static facade over a single shared Repository; it's the usual
entry point. Use Repository directly when you want an isolated instance (DI,
tests, loading multiple file sets). See
API Reference.
get() caches on first read. Call DotENV::flush() (or use a fresh
Repository) to clear the cache. See
Loading & Precedence.
DotENV::reset() drops the shared instance and unloads what it added (leaving
the real environment intact), then call create() again. See
Recipes.
Keep it out of the web root (or block it) and out of version control. A
.env.php additionally executes as PHP — only load trusted ones. See
Security Best Practices.
Yes — it's a standalone loader with no framework ties. Call create() in your
bootstrap and read with get() / env(). If your framework already defines a
global env(), this package's helper steps aside (it only declares env()
when the name is free).
PHP 8.0 through 8.4 (tested on each). For PHP 5.6–7.x, use the 2.0.x
line. See Migration from 2.x.
- Troubleshooting — concrete failures and fixes
- API Reference — every public member
initphp/dotenv · MIT License · part of the InitPHP family
Source · Issues · Discussions · Packagist · Contributing · Security Policy
Getting Started
The .env Format
Core Concepts
Practical Guides
Other