Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I pass a null/empty env variable? #17

Open
ntd1712 opened this issue Jan 21, 2017 · 6 comments
Open

How can I pass a null/empty env variable? #17

ntd1712 opened this issue Jan 21, 2017 · 6 comments

Comments

@ntd1712
Copy link

ntd1712 commented Jan 21, 2017

I currently use "m1/vars": "~1.1"; how can I pass a null/empty env variable?
For example, I have the following settings:

.env file:
DB_PASSWORD=

settings.yml:
password: '%^DB_PASSWORD%'

Setting this will raise a following exception:


An uncaught Exception was encountered
Type: InvalidArgumentException
Message: Variable has not been defined as a DB_PASSWORD: env
Filename: C:\wamp\www\outsource\ci3ng\src\vendor\m1\vars\src\Variables\VariableProvider.php
Line Number: 179

Backtrace:
File: C:\wamp\www\outsource\ci3ng\src\vendor\m1\vars\src\Variables\VariableProvider.php
Line: 152
Function: checkVariableExists

@m1
Copy link
Owner

m1 commented Jan 21, 2017

@ntd1712 Try DB_PASSWORD = null

There may be an issue with trying to pass empty key/values as variables, I'll look into this.

@m1
Copy link
Owner

m1 commented Jan 21, 2017

Wait actually, are you loading the .env file through Vars? If so, use the infile replacement syntax, so password: '%^DB_PASSWORD%' would become password: '%$DB_PASSWORD%'

@ntd1712
Copy link
Author

ntd1712 commented Jan 23, 2017

Second try with password: '%$DB_PASSWORD%', but still not success.

Look at your file src/vendor/m1/vars/src/Variables/VariableProvider.php [line 175], we will see the line where error occurred:
if (($type === 'env' && !getenv($variable)) ||

If we replace it with the following, then it works! =):
if (($type === 'env' && false === getenv($variable)) ||

@peter279k
Copy link
Contributor

@m1. Is any suggestion about the @ntd1712 says?

@Dragonrun1
Copy link

So is this bug being fixed or ?

@m1
Copy link
Owner

m1 commented Feb 16, 2019

Not as of yet, don’t really do much php these days. Happy to take pull requests!

peter279k added a commit to peter279k/Vars that referenced this issue Feb 19, 2019
@peter279k peter279k mentioned this issue Feb 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants