Search by

ENV library

Package info

github.com/krzysztofzylka/env

pkg:composer/krzysztofzylka/env

Statistics

Installs: 2 842

Dependents: 2

Suggesters: 0

Stars: 0

Open Issues: 0

2.0.6 2026-09-21 20:25 UTC

This package is auto-updated.

Last update: 2026-09-21 20:26:03 UTC


README

This class is used for loading and parsing environment variables from a file.

Install

composer require krzysztofzylka/env

Load env file

$env = new \Krzysztofzylka\Env\Env();
$env->loadFromFile('/path/to/env/file');

Load multiple env file

$env = new \Krzysztofzylka\Env\Env();
$env->loadFromFile(['/path/to/env/file', '/path/to/env/file', ...]);

Load from system (getenv())

$env = new \Krzysztofzylka\Env\Env();
$env->loadFromSystem();

Example ENV file content

DB_HOST=localhost
DB_NAME=testDB
DB_USER=username
DB_PASS=password

Value conversion

Values are converted to a PHP type only when it is lossless:

Value Result
true / false / null (any case) bool / null
123, 123.456 int / float
0123456, 1.50, 1.0, integers above PHP_INT_MAX string (converting would change the text)
"123", '123' (quoted number) string
" padded " string, whitespace kept

Variables whose name ends with PASSWORD, PASSWD, PASS, SECRET, TOKEN, SECRET_KEY, API_KEY, PRIVATE_KEY, ACCESS_KEY or AUTH_KEY (e.g. REDIS_PASSWORD, API_TOKEN) are never converted - a password null, true or 0123456 reaches the application exactly as written. Flags such as TOKEN_ENABLED=false are still converted to bool. Env::isSensitiveName($name) exposes this check.

Lines may end with \n, \r\n or \r; variable names are trimmed and upper-cased.

Exceptions

File not found: If the given file path does not exist a File not found exception will be thrown.