PHP: Globals and Superglobals
PHP has a global
keyword and a number of unusual ways of using global variables. Variables declared outside functions have file scope (which is for most purposes the widest scope). However, they are not accessible inside functions unless imported with the global
keyword (i.e., the keyword accesses global variables, it does not declare them).
However, some predefined variables, known as superglobals are always accessible. They are all arrays. A general purpose one is the $GLOBALS
superglobal, which contains all the variables defined out of function scope. Changes to its elements change the original variables, and additions create new variables. The superglobals $_POST
and $_GET
are widely used in web programming.
Read more about this topic: Global Variable