I upgraded my Wordpress instance from 4.5 to 4.8, and for some reason my boolean environment variable is now returning as a string of "false" rather than false
. Since my PHP version hasn't changed, I'm a bit mystified at the change. More importantly however, about going forward, what's the best way to manage getting booleans into PHP via environment vars?
Here's the .env line I have:
WP_FORCE_SSL_ADMIN=false
Here's the line I had in my wp-config.php that is returning true
due to string conversion.
define('FORCE_SSL_ADMIN', getenv('WP_FORCE_SSL_ADMIN'));
Here's the var_dump:
["WP_FORCE_SSL_ADMIN"]=>
string(5) "false"
I know that I can simply refactor the define to account for the string conversion, but I'm bothered that I don't understand what changed when nothing should have. This worked fine on for wordpress version 4.5.
Looking for an answer to explain the best method for passing boolean vars from my environment into PHP, or do I always have to account for the string conversion?
Just in case someone comes here looking for the answer to how I solved it, what I did was simply do a comparison to the string of "true".
define('FORCE_SSL_ADMIN', strtolower(getenv('WP_FORCE_SSL_ADMIN')) === "true");
While this works, it still doesn't feel quite right to me, like I'm missing something.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With