chillerlan / php-dotenv
A simple .env loader - PHP 7.4+
Fund package maintenance!
Ko Fi
Installs: 1 080
Dependents: 9
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
Open Issues: 0
Requires
- php: ^7.4 || ^8.0
Requires (Dev)
- phan/phan: ^3.2.2
- phpunit/phpunit: ^9.4
README
Loads contents from a .env
file into the environment (similar to vlucas/phpdotenv). PHP 7.2+
Documentation
Installation
requires composer
composer.json (note: replace dev-master
with a version constraint)
{ "require": { "php": "^7.4", "chillerlan/php-dotenv": "dev-master" } }
Installation via terminal: composer require chillerlan/php-dotenv
Profit!
Usage
# example .env
FOO=bar
BAR=foo
WHAT=${BAR}-${FOO}
$env = new DotEnv(__DIR__.'/../config', '.env'); $env->load(['foo']); // foo is required $foo = $env->get('FOO'); // -> bar $foo = $_ENV['FOO']; // -> bar $foo = $env->set('foo', 'whatever'); $foo = $env->get('FOO'); // -> whatever
// avoid the global environment $env = (new DotEnv(__DIR__.'/../config', '.env', false))->load(); $foo = $env->get('FOO'); // -> bar $foo = $_ENV['FOO']; // -> undefined