|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #7983 Odd behviour of $GLOBALS
Submitted: 2000-11-26 21:12 UTC Modified: 2000-12-19 06:14 UTC
From: arunas at anm dot org Assigned:
Status: Closed Package: Unknown/Other Function
PHP Version: 4.0.3pl1 OS: Redhat LInux 7.0
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
35 + 7 = ?
Subscribe to this entry?

 [2000-11-26 21:12 UTC] arunas at anm dot org
I don't always know how variable arrives in a script.  To be general, I have a function ClearVar($Name) that accepts the name of a variable, and goes through all of the global arrays to clear it.

This appears to work properly with HTTP_GET_VARS and HTTP_POST_VARS, but the GLOBALS array is a funny fish.

In fact, playing around to try to figure it out, I tried:

$Piano = "Hemmingway";
print "Before: Piano = $Piano<br>\n";
print "After: Piano = $Piano<br>\n";

Which outputs:

Before: Piano = Hemmingway
After: Piano = ??0????

or some variant of that.

More surprisingly, if I use unset on an element of the GLOBALS array within a function even odder things happen.  The following code:

$Piano = "Hemmingway";
print "Before: Piano = $Piano<br>\n";
print "After: Piano = $Piano<br>\n";

$Piano = "Brahmbach";

print "Before: Piano = $Piano<br>\n";
print "After: Piano = $Piano<br>\n";

function ClearTest()
	global $Piano;	
	print "Before[ClearTest]: Piano = $Piano<br>\n";
	print "After[ClearTest]: Piano = $Piano<br>\n";

function MyClearVar($Name)

Produces the following:

Before: Piano = Hemmingway
Before[ClearTest]: Piano = Hemmingway
After[ClearTest]: Piano = Hemmingway
After: Piano = |6(
Before: Piano = Brahmbach
Before[ClearTest]: Piano = 
After[ClearTest]: Piano = 
After: Piano = Brahmbach

So apparently not all is simple with $GLOBALS.  There maybe something I'm missing, I may be abusing a convenience method, but boy are the results strange.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2000-11-27 17:53 UTC]
Well, part of this behavior is really not all that mysterious.

global $Piano;

This create a local variable $Piano, and makes it a reference
to $GLOBALS["Piano"]. Unsetting $Piano does nothing more than
break that reference, as is documented in the incompatibilities
list (
 [2000-12-19 06:14 UTC]
All examples work correctly for me with latest CVS. Please
try latest snapshot at and reopen if it still
happens for you.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Feb 29 03:01:27 2024 UTC