#35117 [NEW]: $_SERVER auto-global not in global scope in included file

From: Date: Sat, 05 Nov 2005 18:39:05 +0000
Subject: #35117 [NEW]: $_SERVER auto-global not in global scope in included file
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-87638@lists.php.net to get a copy of this message
From: ramsey@php.net Operating system: Debian sarge PHP version: 5.1.0RC4 PHP Bug Type: Variables related Bug description: $_SERVER auto-global not in global scope in included file Description: ------------ I noticed the following error after moving a Web site's code to a machine running PHP 5.1RC4: PHP Notice: Undefined variable: _SERVER in /data/home/ramsey/public_html/file.inc on line 2 This didn't make any sense, however for two reasons: 1) I'm able to use $_SERVER in other scripts, and 2) this variable should be an auto-global. The difference with this script, though, is that it is an .inc file that is included and executed within a parent script. If I place "global $_SERVER;" at the top of the included file, then it has access to the $_SERVER auto-global array--on the first load of the page only. Each subsequent load of the page again produces the PHP Notice above. I haven't tested this with other auto-globals, so I don't know whether they have the same problems. I created two simple test scripts to reproduce this (shown in the "reproduce code" section). I noticed that the first time I loaded the page, it showed the $_SERVER array just fine, but on each subsequent load, it generates the undefined variable notice given above. Everytime I make a change (any change) to the page and load it, the array shows up on the first load only. With this in mind, I realized that the problem was probably not with the auto-global array but with APC, which I also have installed (using "pecl install apc" and accepting the default configuration values). When I comment out the APC extension line in php.ini, the $_SERVER array shows up perfectly on each load of the page. Reproduce code: --------------- test.php: <?php include_once 'file.inc'; ?> file.inc: <?php print_r($_SERVER); ?> Expected result: ---------------- I should see the print_r() output of the $_SERVER auto-global array each time the page loads. Actual result: -------------- A PHP notice that occurs each time the page loads (but I noticed that the expected result occurred the first time the page loaded): PHP Notice: Undefined variable: _SERVER in /data/home/ramsey/public_html/file.inc on line 2 -- Edit bug report at http://bugs.php.net/?id=35117&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=35117&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=35117&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=35117&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=35117&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=35117&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=35117&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=35117&r=needscript Try newer version: http://bugs.php.net/fix.php?id=35117&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=35117&r=support Expected behavior: http://bugs.php.net/fix.php?id=35117&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=35117&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=35117&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=35117&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=35117&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=35117&r=dst IIS Stability: http://bugs.php.net/fix.php?id=35117&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=35117&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=35117&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=35117&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=35117&r=mysqlcfg

« previous php.bugs (#87638) next »