A scope is a range that can be used or visible to a variable in a script. PHP has six basic scope rules.
A scope is a range that can be used or visible to a variable in a script. PHP has six basic scope rules.
1. the built-in Super global variables can be used and visible anywhere in the script.
2. constants, a volume declared, can be globally visible; that is, they can be used outside the function.
3. The global variables declared in a script are visible throughout the script, but not inside the function.
4. when the variable used in the function is declared as a global variable, its name must be consistent with the global variable name.
5. variables created inside the function and declared as static cannot be visible outside the function, but they can be kept during multiple execution of the function.
6. the variable created in the function is local to the function. when the function is terminated, the variable does not exist.
Variable scope
$ _ GET and $ _ POST arrays and some other special variables have their own scope rules. These are called Super global variables that can be used and visible anywhere, including internal and external functions.
The complete list of Super global variables is as follows:
1. $ _ GLOBALS, an array of all global variables.
2. $ _ SERVER: an array of SERVER environment variables.
3. $ _ GET: the variable array passed to the script through the GET method.
4. $ _ POST: the variable array passed to the script through the POST method.
5. $ _ COOKIE, cookie variable array.
6. $ _ REQUEST, an array of all user input variables, including the input content contained in $ _ GET, $ _ POST, and $ _ COOKIE.
7. $ _ FILES, an array of variables related to file upload.
8. $ _ ENV, environment variable array
9. $ _ SESSION, an array of SESSION variables.