This article mainly introduces the introduction of PHP superglobals (Superglobals). This article explains the overview, scope of variables, superglobal arrays and precautions For more information, friends who need it can refer to it
Overview
I want to build a WeChat public platform. After reading the sample code for website access provided by WeChat official, I found that there is a problem that seems to be half-understood, which is to use $_GET directly in the class. After carefully checking the knowledge in this area, I found that the basic knowledge of this part of PHP is not very reliable.
Scope of variables
When talking about PHP’s super-global array, we have to talk about the scope of variables. The scope of variables is a concept that exists in any programming language and must be mastered. Regarding the variable scope in PHP, I won’t say more here. You can check the information yourself.
Super global array
Super global arrays are specially defined array variables in PHP. They are called super global arrays because these arrays can be accessed anywhere in the script and in any scope, such as functions, classes, files, etc.
Super global arrays in PHP include the following:
The code is as follows:
$GLOBALS
$_SERVER
$_GET
$_POST
$_REQUEST
$_COOKIE
$_SESSION
$_FILES
$_ENV
Attention
One thing to note is the difference between global variables and superglobal arrays in PHP. Global variables cannot be directly accessed in a class.
Summary
In the future, you should pay more attention to basic knowledge and solve your questions in a timely manner.