getenv() doesn't show all variables, even if they are set

Viewed 495

I'm testing setting environment variables in .htaccess for my php code to use, and facing strange behaviour from the getenv() function.


In my .htaccess, I set

SetEnv BOP 23

And in my php, I successfully get

$res = getenv("BOP");
echo($res);
>>>>  23

But when I try to var_dump(getenv()); or use debugger to see what is in the array returned by getenv(), I get an array of length 23 BUT my "BOP" variable is missing.


For example, if I try to dump getenv() into an array and make a lookup:

$array = getenv();

echo($array["BOP"])

I get an exception:

Exception has occurred.
Notice: Undefined index: BOP

From what I read here about getenv() https://www.php.net/manual/en/function.getenv.php

... If varname is omitted, all environment variables are returned as associative array.

So what am I missing? Why can I access my variable but isn't it in getenv()?

1 Answers

Be shure you use PHP 7.1 or higher

FROM 7.1.0 getenv() no longer requires its parameter. If the parameter is omitted, then the current environment variables will be returned as an associative array.

Related