No, all of you guys are confused.
$var is very clearly set. Read again the line
if($var = getenv($name))
The order of evaluation is as follows.
First, getenv() is called with $name as an argument. If the named environment variable exists, it returns the value of that variable. If not, it returns NULL.
Then, the result of getenv() is assigned to $var.
Then, the result of the assignment -- which is the same as the assigned value -- is tested.
If getenv() returned a value, then the tested value is true (i.e., not false).
If getenv() did not return a value, but rather NULL, then the tested value is false.
The code is correct.