File tree Expand file tree Collapse file tree 1 file changed +9
-20
lines changed Expand file tree Collapse file tree 1 file changed +9
-20
lines changed Original file line number Diff line number Diff line change @@ -57,32 +57,21 @@ BAR=foo
5757WHAT=${BAR}-${FOO}
5858```
5959
60- ``` php
61- class MyClass{
62- use Env;
63-
64- protected $foo;
65-
66- public function __construct(){
67- // load and overwrite existing vars, require var "WHAT"
68- $this->__loadEnv(__DIR__.'/../config', '.env', ['WHAT']);
69-
70- // will not overwrite
71- $this->__addEnv(__DIR__.'/../config', '.env', false, ['WHAT']);
72-
73- $this->foo = $_ENV['WHAT']; // -> foo-bar
74- // or
75- $this->foo = $this->__getEnv('WHAT');
76- }
77- }
78- ```
79-
8060``` php
8161$env = new DotEnv(__DIR__.'/../config', '.env');
8262$env->load(['foo']); // foo is required
8363
8464$foo = $env->get('FOO'); // -> bar
65+ $foo = $_ENV['FOO']; // -> bar
8566
8667$foo = $env->set('foo', 'whatever');
8768$foo = $env->get('FOO'); // -> whatever
8869```
70+
71+ ``` php
72+ // avoid the global environment
73+ $env = (new DotEnv(__DIR__.'/../config', '.env', false))->load();
74+
75+ $foo = $env->get('FOO'); // -> bar
76+ $foo = $_ENV['FOO']; // -> undefined
77+ ```
You can’t perform that action at this time.
0 commit comments