Bug #77782 [Com]: getenv without params returns keys that aren't accessible with $varname param
| From: | danack@php.net | Date: | Sat, 23 Mar 2019 03:30:31 +0000 |
| Subject: | Bug #77782 [Com]: getenv without params returns keys that aren't accessible with $varname param | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-220143@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77782&edit=1
ID: 77782
Comment by: danack@php.net
Reported by: matt at mattallan dot me
Summary: getenv without params returns keys that aren't
accessible with $varname param
Status: Open
Type: Bug
Package: FPM related
Operating System: macOs Mojave 10.14
PHP Version: 7.3.3
Block user comment: N
Private report: N
New Comment:
I can't reproduce this. I've setup a test docker-compose https://github.com/Danack/PhpTest
Cloning that, running "docker-compose up --build" and then going to http://localhost:8080/ shows FOO set to bar correctly.
However, it is a little odd that you have things like SERVER_NAME and DOCUMENT_ROOT set in your
environment variables apparently...those are not meant to be environment variables, but are passed
in a different way for fastcgi. Is there anything funky in your config that is setting those?
Previous Comments:
------------------------------------------------------------------------
[2019-03-22 23:26:24] matt at mattallan dot me
Hi,
I literally set the environment variable
FOO for this reproduction script. The Nginx
config contains fastcgi_param FOO bar;.
I get the following output from the script you included:
string(4) "USER"
string(4) "HOME"
string(15) "HTTP_CONNECTION"
string(11) "HTTP_ACCEPT"
string(20) "HTTP_ACCEPT_ENCODING"
string(15) "HTTP_USER_AGENT"
string(9) "HTTP_HOST"
string(15) "REDIRECT_STATUS"
string(11) "SERVER_NAME"
string(11) "SERVER_PORT"
string(11) "SERVER_ADDR"
string(11) "REMOTE_PORT"
string(11) "REMOTE_ADDR"
string(15) "SERVER_SOFTWARE"
string(17) "GATEWAY_INTERFACE"
string(14) "REQUEST_SCHEME"
string(15) "SERVER_PROTOCOL"
string(13) "DOCUMENT_ROOT"
string(12) "DOCUMENT_URI"
string(11) "REQUEST_URI"
string(11) "SCRIPT_NAME"
string(14) "CONTENT_LENGTH"
string(12) "CONTENT_TYPE"
string(14) "REQUEST_METHOD"
string(12) "QUERY_STRING"
string(3) "FOO"
string(15) "SCRIPT_FILENAME"
string(9) "FCGI_ROLE"
string(8) "PHP_SELF"
string(18) "REQUEST_TIME_FLOAT"
string(12) "REQUEST_TIME"
bool(false)
string(3) "bar"
string(3) "FOO"
Using the Caddy webserver with the configuration directive env FOO bar I get this
output:
string(4) "USER"
string(4) "HOME"
string(11) "REMOTE_ADDR"
string(12) "REMOTE_IDENT"
string(11) "HTTP_ACCEPT"
string(3) "FOO"
string(11) "REQUEST_URI"
string(11) "SERVER_NAME"
string(14) "REQUEST_SCHEME"
string(9) "PATH_INFO"
string(12) "CONTENT_TYPE"
string(15) "SCRIPT_FILENAME"
string(15) "SERVER_PROTOCOL"
string(12) "QUERY_STRING"
string(11) "REMOTE_USER"
string(11) "REMOTE_HOST"
string(12) "DOCUMENT_URI"
string(13) "DOCUMENT_ROOT"
string(15) "SERVER_SOFTWARE"
string(14) "REQUEST_METHOD"
string(17) "GATEWAY_INTERFACE"
string(9) "AUTH_TYPE"
string(15) "HTTP_USER_AGENT"
string(11) "SCRIPT_NAME"
string(9) "HTTP_HOST"
string(11) "SERVER_PORT"
string(11) "REMOTE_PORT"
string(14) "CONTENT_LENGTH"
string(9) "FCGI_ROLE"
string(8) "PHP_SELF"
string(18) "REQUEST_TIME_FLOAT"
string(12) "REQUEST_TIME"
bool(false)
string(3) "bar"
string(3) "FOO"
I created a gist with the exact Caddyfile I am using here: https://gist.github.com/matt-allan/280a0120d7e8467fb384acd80d697edb
Thanks,
Matt
------------------------------------------------------------------------
[2019-03-22 22:51:38] danack@php.net
To be clear, are you seeing this with 'FOO' or is foo being used as a metasyntatic name?,
Also, please could you run and show the output of:
$env = getenv();
foreach ($env as $key => $value) {
var_dump($key);
}
$var = 'FOO';
var_dump(getenv($var));
var_dump($env[$var]);
var_dump($var);
with FOO replaced by the actual name if it isn't FOO.
------------------------------------------------------------------------
[2019-03-22 20:52:46] matt at mattallan dot me
Description:
------------
PHP version:
PHP 7.3.3 (cli) (built: Mar 8 2019 16:40:07) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.3, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.3, Copyright (c) 1999-2018, by Zend Technologies
(installed with Homebrew)
Relevant ini params:
variables_order = "EGPCS"
auto_globals_jit = Off
Overview:
I set the environment variable FOO using the fastcgi_param in my Nginx configuration.
If I make a HTTP request to the server I am able to access the environment variable using
getenv()['FOO'] but I am not able to access the environment variable using
getenv('FOO').
The same issue occurs with the Caddy server. If I set the environment variable in the fpm
configuration using env[FOO]=bar the issue does not occur. If I run the script from
the CLI or the built in web server it works as expected.
Test script:
---------------
<?php
$env = getenv();
var_dump(array_key_exists('FOO', $env));
var_dump($env['FOO']);
var_dump(getenv('FOO'));
Expected result:
----------------
I expect to see the output:
bool(true)
string(3) "bar"
string(3) "bar"
Actual result:
--------------
I see the output:
bool(true)
string(3) "bar"
bool(false)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77782&edit=1