ez-php/dotenv

Lightweight .env file loader for PHP — supports quoted values, variable interpolation, and immutable loading

Maintainers

Package info

github.com/ez-php/dotenv

pkg:composer/ez-php/dotenv

Statistics

Installs: 46

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

0.2.0 2026-03-15 03:47 UTC

This package is auto-updated.

Last update: 2026-03-15 04:17:51 UTC


README

Lightweight .env file loader for PHP — supports quoted values, variable interpolation, and immutable loading. Zero dependencies.

CI

Requirements

  • PHP 8.5+

Installation

composer require ez-php/dotenv

Usage

use EzPhp\Env\Dotenv;

// Load .env from the project root (immutable — never overwrites existing env vars)
Dotenv::createImmutable(__DIR__)->load();

// Silently skip if the file doesn't exist (useful in production)
Dotenv::createImmutable(__DIR__)->safeLoad();

// Custom filename
Dotenv::createImmutable(__DIR__, '.env.testing')->load();

Variables are written to $_ENV, $_SERVER, and getenv().

Supported syntax

# Comments are ignored
APP_NAME=My App
APP_ENV=production

# Quoted values preserve whitespace and support escapes
GREETING="Hello, World!\nWelcome."

# Single-quoted values are literal — no interpolation, no escapes
LITERAL='value with $dollar and \n backslash'

# Variable interpolation in double-quoted values
BASE_URL=https://example.com
API_URL="${BASE_URL}/api/v1"

# export prefix is stripped
export SECRET_KEY=abc123

# Empty values
EMPTY=

Immutability

Variables already present in the environment (set before loading) are never overwritten. This means real environment variables (e.g. set in Docker or CI) always take precedence over .env file values.

License

MIT — Andreas Uretschnig