php-standard-library/env
Tiny PHP utility for reading environment variables with sensible defaults and type casting. Helps centralize access to config via env(), supports required keys, fallback values, and safe handling when variables are missing or empty.
.env handling.getenv()/$_ENV usage with a typed, maintainable API, easing onboarding for new developers.env() helpers) for high-throughput systems.Adopt if:
getenv(), $_ENV, or framework-specific helpers).bool for feature flags or int for timeouts) without heavy dependencies.getenv() is overused, and you need a low-risk, drop-in replacement.Look elsewhere if:
vlucas/phpdotenv + symfony/validator.spatie/laravel-encryption or HashiCorp Vault.env() helpers + .env files.php-option/env or custom solutions.For Executives:
*"This package lets us eliminate configuration chaos in our PHP services. Right now, environment variables are handled inconsistently—some use raw getenv(), others rely on framework quirks, and CI/CD pipelines break when configs are missing. By adopting this lightweight, typed solution, we’ll:
true vs. 'true' for booleans).getenv() calls with a clean API.For Engineering Teams:
*"This is a drop-in replacement for getenv()/$_ENV that gives us:
bool, int, or string values at parse time (e.g., env('DEBUG', false) returns a boolean).env('DATABASE_URL', 'sqlite:///:memory:')) prevent runtime crashes.getenv('KEY') with env('KEY') in stages. Works alongside existing .env files. Let’s prototype it in one service first (e.g., the API gateway) to validate the win."*For Developers: *"Tired of:
if (getenv('FEATURE_X') === 'true') { ... } // What if it's '1'? 'yes'? NULL?
Now you get:
if (env('FEATURE_X', false)) { ... } // Always a boolean.
composer require php-standard-library/env and go.
Start with one class (e.g., ConfigService) and expand as needed."*How can I help you explore Laravel packages today?