PHP Problems

$GLOBALS Overwrite and it’s Consequences

Last update: 2. November 2005

In PHP exists a special group of variable arrays called the superglobals. These variables have im common, that they are known to all variable scopes and therefore can be accessed from within any function or method without hassle. They are used within PHP to store the among other things the GET, POST, COOKIE and SESSION variables. However one of the superglobals, that is called $GLOBALS is special in two ways. Firstly it is merely a reference to the global symbol table, because it’s purpose is to access variables from the global symbol table from within functions or methods in an easy way. Secondly it is implemented in a different way, than the rest of the superglobals and therefore unexpected things may happen when the $GLOBALS variable is overwritten.


To properly understand the problems that can arise when $GLOBALS is overwritten it is necessary to have a look on how it is implemented within the different major versions of PHP. In PHP4 $GLOBALS is created by the executor whenever the execution of the main program, a function, a method or evaluated code is started. This is done by inserting the key ‘GLOBALS’ into the current local symbol table as a reference to the global symbol table. This can however fail if the local symbol table already contains an element called ‘GLOBALS’. The problem with this behaviour is, that when GLOBALS is overwritten in one variable scope (f.e. in the scope of the main program) it gets a different meaning and content, than GLOBALS in the scope of subfunctions, because for those the GLOBALS variable is recreated. This means after it is overwritten within a variable scope it looses the binding to the global symbol table and therefore it is no longer pointing to the global variables.

Read more at:

You can leave a response, or trackback from your own site.

One Response to “PHP Problems”

  1. l-theanine says:

    You have noted very interesting details! ps nice website.

Leave a Reply

Designed for Ares Galaxy in Collaboration with Hostgator coupons and Popular Wordpress Themes and unlock iphone 5