Bug #69081 [Opn->Csd]: $_SERVER variable sometimes undefined

From: Date: Wed, 12 Jul 2017 15:20:58 +0000
Subject: Bug #69081 [Opn->Csd]: $_SERVER variable sometimes undefined
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-210017@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69081&edit=1

 ID:                 69081
 Updated by:         ab@php.net
 Reported by:        djbrainnrg at gmail dot com
 Summary:            $_SERVER variable sometimes undefined
-Status:             Open
+Status:             Closed
 Type:               Bug
 Package:            Unknown/Other Function
 Operating System:   Windows 7 64bit
 PHP Version:        master-Git-2015-02-19 (snap)
-Assigned To:        
+Assigned To:        ab
 Block user comment: N
 Private report:     N

 New Comment:

These issues are fixed in PHP 7.2. Please test the 7.2 pre releases and file a bug if you still
experience these issues.

Thanks.


Previous Comments:
------------------------------------------------------------------------
[2015-12-17 22:27:28] rm dot phpbt at romanrm dot net

I run into the same issue with _REQUEST.

The code below (from tt-rss):

---
<?php
...
	if (get_magic_quotes_gpc()) {
		function stripslashes_deep($value) {
			$value = is_array($value) ?
				array_map('stripslashes_deep', $value) : stripslashes($value);
				return $value;
		}

		$_POST = array_map('stripslashes_deep', $_POST);
		$_GET = array_map('stripslashes_deep', $_GET);
		$_COOKIE = array_map('stripslashes_deep', $_COOKIE);
		$_REQUEST = array_map('stripslashes_deep', $_REQUEST);
	}

	$op = $_REQUEST["op"];
---

always fails to work properly, with "PHP Notice:  Undefined variable: _REQUEST" in the
last line.

However adding a simple line:

$_REQUEST;

into the beginning of the script does work-around the issue.

------------------------------------------------------------------------
[2015-09-06 10:37:14] spl1nes dot com at googlemail dot com

I encountered this as well. It seems like the complexity of the script also plays a very important
role. A one liner will never have this bug but a more complex/longer execution script can cause this
bug.

I even did a var_dump($_SERVER); at the entry point of my application (without any prior
modification) and in 2% of the executinos it resulted in a undefined variable notice. If I
don't use a var_dump right at the entry point and access $_SERVER at a later point there is a
higher chance of a undefined variable notice.

I highly assume this is related to auto_globals_jit = On. Once I turned it off I never had this
problem.

------------------------------------------------------------------------
[2015-07-28 14:20:22] riggsfolly at gmail dot com

Ditto the report by (dominique at ottello dot net)

Except that :

Windows 7 Pro 32 bits
Wamp with Apache 2.4.9 32 bits
PHP 7 Beta 2 from http://windows.php.net/downloads/qa/php-7.0.0beta2-Win32-VC14-x86.zip

Odd error still exists, but a simple script like,

<?php
$server_software = $_SERVER['SERVER_SOFTWARE'];
echo $server_software;

Works every time with no errors reported.

------------------------------------------------------------------------
[2015-06-14 14:13:35] dominique at ottello dot net

Hi,
Windows 7 Pro 64 bits
Wamp with Apache 2.4.12 32 bits
PHP 7 Alpha 1 from http://windows.php.net/downloads/qa/php-7.0.0alpha1-Win32-VC14-x86.zip
The index.php file has always error :
[14-Jun-2015 08:56:44 UTC] PHP Notice:  Undefined variable: _SERVER in J:\wamp\www\index.php on line
25
Line 25 $server_software = $_SERVER['SERVER_SOFTWARE'];

I use $_SERVER['SERVER_SOFTWARE'] in another file : aviatechno/test/essais.php
echo "<p>SERVER_SOFTWARE   =".$_SERVER['SERVER_SOFTWARE']."|
</p>\n";
without error.

------------------------------------------------------------------------
[2015-02-20 20:55:29] djbrainnrg at gmail dot com

Ah sorry, here the code that throws the error.

public function getHost(){
    return getValueFromArray($_SERVER, "HTTP_HOST");
}

and getValueFromArray is

function getValueFromArray(array $arr, $key){
    if(isset($arr[$key])){
        return $arr[$key];
    }
    $levels = explode("[", $key);
    $c = count($levels);
    foreach($levels as $k => $level){
        $level = trim($level, "[]");
        if(!isset($arr[$level])){
            return NULL;
        }
        $arr = $arr[$level];
    }
    return $arr;
}

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=69081


--
Edit this bug report at https://bugs.php.net/bug.php?id=69081&edit=1


Thread (9 messages)

« previous php.bugs (#210017) next »