oscarotero/env
oscarotero/env is a simple PHP library to read environment variables and convert them to typed values (bool, int, float, arrays, etc.), with support for .env files, defaults, and nested variable expansion. Lightweight and dependency-free alternative to phpdotenv.
Architecture fit. oscarotero/env is a zero-dependency, single-purpose PHP utility that reads environment variables and coerces them to scalar/array types (Env::bool(), Env::int(), Env::float(), Env::array(), Env::oneOf()), with an optional lightweight .env loader (Env::init()). Architecturally it sits in the same layer Laravel already owns: vlucas/phpdotenv (bundled with the framework) plus the env() helper. That makes the fit narrow but real — it is genuinely useful for non-Laravel PHP services, CLI tools, and shared libraries that need typed env reads without pulling in the framework, and it is largely redundant inside a standard Laravel application. The differentiator is not loading .env; it is deterministic typed access with a readable API.
Integration feasibility. Low effort. composer require oscarotero/env, one class, no PHP extensions, no service provider required. A proof of concept is an afternoon. The real integration question is coexistence: running this loader alongside phpdotenv invites precedence ambiguity across getenv(), $_ENV, and $_SERVER, and Laravel's config:cache already makes runtime env() calls unreliable — a constraint this package does not remove.
Technical risk. Technically low; supply-chain and ownership risk is moderate-to-high. Ninety stars, effectively a single maintainer, small community, no formal security posture. The behavior is sensitive to environment resolution order and putenv semantics, which is subtle under PHP-FPM and long-running workers (Octane/Swoole) where env is frozen at boot. Type coercion is opinionated — "false", "0", "", "null" — and silent mis-coercion is the most likely production defect.
Key questions for engineering.
env() + phpdotenv does not already solve?.env loader, or both? Only the former is differentiated.phpdotenv or run alongside it — and who owns the precedence contract?.env parsing edge cases (quotes, escapes, multiline, interpolation) a divergence risk from phpdotenv?Stack fit. Compatible with any Composer/PSR-4 PHP application on a supported PHP 8.x line. In Laravel, confine usage to bootstrap/ and config/*.php only — never in runtime application code, because config:cache bakes values and makes late env reads unreliable regardless of library.
Migration path. This is not a rip-and-replace for phpdotenv inside Laravel; the framework's bootstrapper already loads .env and removing it is high-friction, low-reward. The pragmatic path: adopt only where a typed-read gap genuinely exists (internal tools, non-Laravel services, packages shared across frameworks). If migrating, move config files first, then bootstrap, then remove the old loader — and only in services where phpdotenv is not framework-provided.
Compatibility. Verify PHP version support against our matrix; test resolution order against existing .env files; confirm interaction with Laravel's Dotenv bootstrapper and hosts where putenv is disabled; validate behavior under Octane/Swoole. Pin the exact version and add it to dependency-policy review.
Sequencing.
.env corpus and diff coerced output vs. env().Env facade so call sites can be swapped back to native env() without churn.Maintenance. Very low code churn; the December 2024 release indicates the project is alive but slow-moving. The operational cost is governance, not patching: version pinning, quarterly dependency review (~1–2 days/quarter), and a documented contingency to fork or vendor the single class if the maintainer goes dark.
Support. Minimal expertise required — the API is readable in an afternoon. The real support risk is knowledge concentration around resolution order and coercion rules; write it down or it becomes tribal knowledge.
Scaling. Negligible runtime cost — parsing happens once at boot, no I/O beyond a single file read, no state. The scaling concern is correctness uniformity across services (mixed env semantics), not throughput.
Failure modes.
"false" vs "0" vs "" vs "null").phpdotenv load the same .env.config:cache.env() expectations..env parser divergence from phpdotenv on quotes, escapes, and multiline values.Ramp-up. Half a day to prototype; one to two days to productionize behind a wrapper with tests and documentation. The larger organizational cost is the decision itself: justifying a second env-reading dependency in a framework that already ships one.
How can I help you explore Laravel packages today?