php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #56629 APC removes $_SERVER from global scope
Submitted: 2005-11-05 14:06 UTC Modified: 2005-11-05 14:08 UTC
From: ramsey@php.net Assigned:
Status: Duplicate Package: APC (PECL)
PHP Version: Irrelevant OS: Debian sarge
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ramsey@php.net
New email:
PHP Version: OS:

 

 [2005-11-05 14:06 UTC] ramsey@php.net
Description:
------------
I noticed the following error after moving a Web site's code to a machine running PHP 5.1RC4 and APC (downloaded with pecl):

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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-11-05 14:08 UTC] rasmus@php.net
This has been reported a few times.  I haven't gotten around to fixing it, but the workaround is trivial.  Turn off auto_globals_jit in your config.
 [2008-02-12 03:55 UTC] canman888 at gmail dot com
Can it really be that this is still an issue?
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Jun 19 13:01:26 2019 UTC