-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
vars in .env sometimes returns null #3992
Comments
I just ran into this problem myself!
This is on macOS with PHP 7.3.26 and apache installed using homebrew. |
OK, very scary - I have changed my non-working code from if (getenv('CI_ENVIRONMENT') === 'development') {
// Do something
} to if (getenv('CI_ENVIRONMENT', true) === 'development') {
// Do something
} The second argument to |
Of course! I do not know why the problem is due, I experienced it using getenv and it did not work after I used env () and apparently it was solved, now that I am working on another project I used env () and I experienced the null return of a variable, I couldn't see what the problem was and better I wrote a custom configuration file in config / |
I think this is not a CI4 thing. According to php.net:
|
@luispastendev when you are using |
@paulbalandan Yes! I'm using phpunit, for example right now I run a test taking some configuration variables that I load in my class to use in other methods but when I run my test the variables return null, if I pass the second parameter to env ('foo' , true), it returns true which causes my tests to fail, at the moment I have passed my configuration variables to a php file. my .env file |
@luispastendev if you mean unit testing using PHPUnit when the env variables return |
Can you try the latest develop to see if you're issue is solved? |
@paulbalandan That solved the problem in the tests, thank you very much! If I have problems again I will raise a new issue, thank you very much for your time! |
Glad we've sorted out this tricky issue. Closing this now. |
I don't know why this behavior is caused but sometimes the variables saved in the codeigniter .env file return null
I am trying to test a class and it stopped working because it started to return null, the strange thing is that in other parts of the application I call the variable in the same way and there is no problem
for example:
my class:
my .env file
When I run my test it fails because the environment variable returns null, I had long ago noticed that error in another project where I used the
env ('CI_ENVIRONMENT')
which in the same way did not return the configured environment.I hope someone knows something about this problem :(
The text was updated successfully, but these errors were encountered: