|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #21006 $_Server variables are not global
Submitted: 2002-12-14 01:26 UTC Modified: 2002-12-14 20:47 UTC
From: briantmeyer at earthlink dot com Assigned:
Status: Not a bug Package: IIS related
PHP Version: 4.3.0RC3 OS: win 2000 server
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.
Bug Type:
From: briantmeyer at earthlink dot com
New email:
PHP Version: OS:


 [2002-12-14 01:26 UTC] briantmeyer at earthlink dot com
On my IIS Server, now running 4.3.0RC3 ( i just installed 
and tested it, started writing issue with RC2),
$_Server variables are not global, they don't work inside 
specifically $agent =?$_SERVER["HTTP_USER_AGENT"];

I hear that *nix machines do not have this issue.

The following does not work, there is no variable set for 
the user agent and i get an error.
  function whatever()
  $agent =?$_SERVER["HTTP_USER_AGENT"];

Parse error: parse error, unexpected T_VARIABLE in c:\
inetpub\wwwroot\admin\index.php on line 26
PHP Parse error: parse error, unexpected T_VARIABLE in c:\
inetpub\wwwroot\admin\index.php on line 26

Basically the variable is not set. 

This does work outside the function however

    $agent = $_SERVER["HTTP_USER_AGENT"];

(i coded this to explain issue more simply, 
originally got help at
which has more specific details, example code and the like)

$_SERVER["HTTP_USER_AGENT"]; is global in scope but is not 
accessable in my installation inside a function.
I now use define to pass variable down to my function and 
avoid any more issues personally.

I have a feeling it has to do with my using release 
candidate 2 but do not wish to test with previous versions 
of php at this time.

This seems like an IIS quirk as the forum moderator seemed 
not to have this issue and agreed $_SERVER variables are 
global in scope, as is my understanding from was what i 
read in the manual.

info from my phpinfo()
PHP Version 4.3.0RC2
System 	Windows NT localhost 5.0 build 2195 
Build Date 	Nov 27 2002 21:11:38 
Server API 	CGI/FastCGI 
register globals is also on for the time being, (seems like 
this is always asked)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-12-14 01:49 UTC] briantmeyer at earthlink dot com
RC3 seems to have fixed it weird character ahowing up in 
front of $
 [2002-12-14 12:17 UTC]
Some thoughts:

a) That error has nothing to do with undefined or "non global" variables.  It's a parse error.
b) Variables are case sensitive, never write $_Server it's ALWAYS $_SERVER
c) A weird character?

I really don't think this was ever an error in PHP and has to do with your code only, PHP won't put weird characters in your code.  I blame your text editor.  Try this test:

echo foo();

function foo() {

What text editor do you use to write code?
 [2002-12-14 20:47 UTC] briantmeyer at earthlink dot com
I use bbedit, i am pretty sure it is rock solid editor, not 
sure where the weird character is coming from, probably 
golive which i use sometimes, but that is a side issue.

It was only in release candidate 2. Submitting the bug was 
a mistake since it works in RC3, therefore i marked it 
bogus--i did not shift refresh and was accessing a cached 
page and also had an extended character after the $ on that 

I did a function, basically same as yours and it gave 
error. I then deleted what made it a function, and it 
worked, nothing else changed except code going through 
function. I did this multiple times just adding in the 
function part. Then i saw RC3 was up (as i could not select 
RC2) so i installed it and did the same test again right 
before submitting bug. I tested it quickly as i double 
checked as posting. After posting I saw the "weird" 
character, a "diamond" and looked at it again. It wasn't 
until a shift refresh that it started working so i marked 
it bogus. 

The unexpected T_VARIABLE shows up when i use a undefined 
variable, like the $_SERVER 'query' one, it errors when 
there is no ?whatever=foo in the query but works fine 
otherwise which made me do the isset(). This also happened 
in my functions. The weird character gives another error 
but i can't remember, but i have run into it a few times 
and it is easy to fix with a zap gremlins. (At least that 
has been what happens in my trial and error approach)

Using beta versions is prone to errors by it's nature, it 
seems like it is an issue that basically was corrected on 
its own. I can also say all the code i was trying to use as 
it was also started working with RC3. I really can't 
beleive how error free the release candidates are, or how 
fast development is going. I can see PHP being the standard 
within 5 years if this is kept up.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Mon Mar 20 19:03:41 2023 UTC