mykehowells/dotenv
Load and manage environment variables in PHP/Laravel using .env files. Simple API for reading config values across local, staging, and production setups, making it easy to keep secrets and per-environment settings out of code.
.env handling, reducing cognitive friction for teams familiar with Laravel’s ecosystem.config() and env() helper functions, enabling seamless adoption for Laravel developers transitioning to non-Laravel PHP projects..env features like validation, casting, or nested dot notation (e.g., DATABASE_CONNECTION.mysql.host).config('app.env')).getenv(), putenv()) or needing a lightweight alternative to vlucas/phpdotenv..env system. This package offers no incremental value and risks redundancy..env syntax (e.g., CLI tools, microservices).vlucas/phpdotenv variants it may resemble)..env file validation (e.g., required keys, type casting)..env.production, .env.local).getopt() or Symfony’s Dotenv component.vlucas/phpdotenv or Symfony’s Dotenv?
env('APP_DEBUG')) without Laravel’s framework?phpoption/env)?.env parsing vulnerabilities (e.g., path traversal, injection)?symfony/dotenv)?.env convenience is desired.vlucas/phpdotenv or Laravel’s built-in .env loader (risk of duplicate loading)..env usage (e.g., keys, validation rules, environment-specific files).config()/env() helpers to identify gaps.getenv() calls with env('KEY') in a sandboxed component.composer.json:
"require": {
"mykehowells/dotenv": "^1.0"
}
index.php or bootstrap:
require __DIR__.'/vendor/autoload.php';
Dotenv\Dotenv::create(__DIR__)->load();
bootstrap/app.php to load this package before Laravel’s .env loader (risky; prefer native Laravel).env('KEY') matches Laravel’s behavior (e.g., APP_DEBUG defaults to false).env('DB_HOST', 'localhost')).create_function() or undefined behavior with new features).env() helper is hardcoded to use its own loader. Mixing this package will cause conflicts..env location) must be manual.getenv() calls with env('KEY') in non-critical paths..env.production) to match Laravel’s conventions.env() calls in a service class).symfony/dotenv) in parallel.env() calls in a shim layer.file_exists(), parse_ini_string())..env best practices, but no direct support..env files)..env file is missing or unreadable..env.example templates (common in Laravel).env() calls..env files are parsed once per request (like Laravel’s loader).config() cache, this package reloads .env on every request..env is local to each instance (same as Laravel).| Failure Scenario | Impact | Mitigation |
|---|---|---|
.env file missing/unreadable |
env() returns null silently |
Add fallback: env('KEY', default) |
Malformed .env (e.g., unquoted =) |
Parsing errors or incorrect values | Validate .env files pre-deployment |
| PHP 8.x upgrade | Runtime errors (deprecated features) | Fork/replace with symfony/dotenv |
| Key collision with Laravel | Undefined behavior if mixed | Isolate to non-Laravel components |
| Security misconfigurations | Hardcoded secrets in code | Use env() consistently; avoid getenv() |
How can I help you explore Laravel packages today?