The scope of a variable is the context within which it is defined. For the most part all PHP variables only have a single scope.
PHP organizes code into functions. Functions allow you to group a chunk of code together and execute that code by its name. To keep variables in your code separate from variable sin functions, PHP provides separate storage of variables witin each function. This separate storgae space means that the scope is the local storage of the function.,
Global variables allow you to cross the boundary between separate functions to access a variable's value. The global statement specifies that you want the variables to be the same variable everywhere that it's defined as global.
Static variables provide a variable that is not destroyed when a function ends. You can use the static variable value again the next time you call the function, and it will still have the same value as when it was last used in the function.
Super global variables, called super globals, provide information about the PHP script's environment. These variables don't need to be declared as global. They are automatically available, and they provide important information beyond the script's code itself, such as values from a user's input. Here they are:
Variables | Description |
---|---|
$GLOBALS | Contains a reference to every variable which is currently available within the global scope of the script. The keys of this array are the names of the global variables. |
$_SERVER | Contains information about the Web server environment. |
$_GET | Contains information from GET requests (a form submission). These values should be checked before use. |
$_POST | Contains information from POST requests (a form submission). These values should be checked before use. |
$_COOKIE | Contains information from HTTP cookies. |
$_FILES | Contains information from POST file uploads. |
$_ENV | Contains information about the scripts environment. |
$_REQUEST | Contains information from user inputs. These values should be checked before use. |
$_SESSION | Contains information from any variables registered in a session. |