The environment variable manager makes it easy to manipulate your environment variables in your projects.
composer require phant/env
PHP 8.1
Composer
for dependencies management (PHP)
If the variable is not defined, an exception will be thrown.
use Phant\Env\Manager as Env;
echo Env::get('MY_VAR');
use Phant\Env\Manager as Env;
echo Env::get('MY_VAR', 'default value');
If the variable is already defined, an exception will be thrown.
use Phant\Env\Manager as Env;
echo Env::set('MY_VAR', 'my new value');
use Phant\Env\Manager as Env;
echo Env::set('MY_VAR', 'my new value', true);