Download the PHP package phpdot/env without Composer
On this page you can find all versions of the php package phpdot/env. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package env
phpdot/env
Typed, schema-validated, immutable .env configuration for modern PHP.
Install
Zero dependencies. Pure PHP 8.3+.
Quick Start
Two access patterns are supported — pick whichever fits your bootstrap.
Instance-based
Global facade (recommended for app bootstrap)
Env::init() is a thin wrapper over safeCreate() — missing .env files are silently skipped, schema defaults are used. The global env() helper reads from the singleton.
Every value is typed. Every key is validated. Every access is a pure array lookup.
Architecture
Schema
The schema is the source of truth. Every env var must be declared.
Type System
| Type | PHP return | Example |
|---|---|---|
STRING |
string |
APP_NAME=MyApp → "MyApp" |
INT |
int |
PORT=8080 → 8080 |
FLOAT |
float |
RATE=1.5 → 1.5 |
BOOL |
bool |
DEBUG=true → true |
ENUM |
BackedEnum |
ENV=production → AppEnv::PRODUCTION |
LIST |
list<string> |
IPS=a,b,c → ["a","b","c"] |
JSON |
mixed |
CFG={"a":1} → ["a" => 1] |
Bool recognizes (case-insensitive): true/false, 1/0, yes/no, on/off.
Constraints
| Constraint | Applies to | Example |
|---|---|---|
required |
All | Key must exist or have default |
not_empty |
All | '' after trim fails |
min |
INT, FLOAT | 'min' => 1 |
max |
INT, FLOAT | 'max' => 65535 |
allowed |
STRING | 'allowed' => ['debug', 'info'] |
pattern |
STRING | 'pattern' => '/^https?:\/\//' |
sensitive |
All | Masked in allMasked() |
Multi-File Loading
Files load in order. Later files override earlier ones.
Cross-file interpolation works:
.env Syntax
Values
Escapes (double-quoted only)
Comments
Multiline
Interpolation
Export Prefix
Safe Loading
For Docker/k8s where .env may not exist:
Missing files are silently skipped. Schema defaults are used.
Testing
Instance API
Beyond get(), the Env instance exposes:
| Method | Returns | Purpose |
|---|---|---|
$env->get($key) |
mixed (typed) |
Throws SchemaException on unknown key |
$env->has($key) |
bool |
True if explicitly set in a .env file (not just defaulted) |
$env->all() |
array<string, mixed> |
All typed values, including defaults |
$env->allMasked() |
array<string, mixed> |
Same, but sensitive keys replaced with *** |
$env->getRaw($key) |
string\|null |
Raw string before type cast |
$env->getSchema() |
EnvSchema |
The compiled schema |
$env->getLoadedFiles() |
list<string> |
Paths of .env files actually parsed |
$env->compile($path) |
void |
Write a cache file for fast worker boot |
The static facade exposes a parallel surface: Env::env($key, $default), Env::getInstance(), Env::resetInstance() (testing).
Sensitive Values
allMasked() is safe for logging and error reports.
Config Caching
For production — skip parsing on every worker boot:
Opcache caches the compiled file. Zero disk I/O, zero parsing per worker.
EnvEditor (CLI Only)
Write tool for setup wizards and deployment scripts.
Preserves comments, blank lines, and key order.
Parsing a String
Swoole Safety
Env is immutable. readonly arrays. Zero mutation methods. Two safe patterns:
Package Structure
Development
License
MIT