Bug #69081 [Com]: $_SERVER variable sometimes undefined

From: Date: Sun, 06 Sep 2015 10:37:17 +0000
Subject: Bug #69081 [Com]: $_SERVER variable sometimes undefined
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-195800@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 Comment by: spl1nes dot com at googlemail dot com Reported by: djbrainnrg at gmail dot com Summary: $_SERVER variable sometimes undefined Status: Open Type: Bug Package: Unknown/Other Function Operating System: Windows 7 64bit PHP Version: master-Git-2015-02-19 (snap) Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [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; } ------------------------------------------------------------------------ [2015-02-19 19:35:57] requinix@php.net So what's in Request.class.php on line 198? Needing "$_SERVER;" or needing to disable JIT suggests you have some sort of variable-variables stuff going on. PHP creates $_SERVER (and others) when it's detected in code so if there's some execution path where that doesn't happen before you try to do, say, $GLOBALS["_SERVER"], then you'll have this problem. ------------------------------------------------------------------------ [2015-02-19 14:31:59] djbrainnrg at gmail dot com Here is my phpinfo page http://i.imgur.com/qLasmoY.png ------------------------------------------------------------------------ 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

« previous php.bugs (#195800) next »