PHP has pre-defined 9 Super global variables, 8 magic variables, and 13 magic functions, which can be used anywhere in the script without a declaration. These variables and functions are frequently used in PHP development, and these variables and functions can easily help us solve many problems. The following is a detailed explanation of the super global variables, magic variables, and magic functions in PHP.
PHP Super Global Variables (9)
$GLOBALS store variables in the global scope
$_server Getting server-related information
$_request getting the parameters for post and get requests
$_post get the form's POST request parameters
$_get GET request parameters for a form
$_files get the variable to upload the file
$_env getting an array of server-side environment variables
$_cookie Browser COOKIE operation
Set Cookie:setcookie (name, value, expire, path, domain);
Get cookie:$_cookie["user"];
Delete Cookie:setcookie ("User", "", Time ()-3600);//Set Expiration
Operation of $_session server SESSION
Be sure to Session_Start () Start session before using the session
Storage session:$_session["name"]= "King";//Array operation
Destroy Session:unset ($_session["name"]);//Destroy A
Session_destroy () and unset ($_session);//Destroy All SESSION
PHP Magic variables (8)
The current line number in the __line__ file.
The full path and file name of the __file__ file. If used in the included file, returns the file name that is included.
The directory where the __dir__ file resides. If used in the included file, returns the directory where the included files are located.
The __FUNCTION__ constant returns the name of the function when it is defined
The __CLASS__ constant returns the name of the class when it is defined (case-sensitive).
The method name of the __method__ class (PHP 5.0.0 new addition). Returns the name of the method when it is defined (case-sensitive).
__NAMESPACE__ the name of the current namespace (case sensitive). This constant is defined at compile time (PHP 5.3.0 is new).
PHP Magic Functions (13)
__construct () is called when an object is instantiated, and when __construct and a function with a class name are present, __construct is called and the other is not called.
__destruct () is called when an object is deleted or when an object operation terminates.
The __call () object invokes a method that is called directly if the method exists, or calls the __call function if it does not exist.
__get () When the property of an object is read, the property value is returned directly if it exists, and the __get function is called if it does not exist.
__set () Sets the property of an object, assigns the value directly if the attribute exists, or calls the __set function if it does not exist.
__tostring () is called when an object is printed. such as Echo $obj; or print $obj;
__clone () is called when the object is cloned. such as: $t =new Test (); $t 1=clone $t;
__sleep () serialize was called before. If the object is relatively large, want to cut a bit of the east and then serialize, you can consider this function.
__wakeup () Unserialize is called to do some initialization of the object.
__isset () is called when detecting whether an object's properties exist. such as: Isset ($c->name).
__unset () is called when a property of an object is unset. such as: unset ($c->name).
Called when the __set_state () call is Var_export. Use the return value of __set_state as the return value of Var_export.
__autoload () When an object is instantiated, the method is called if the corresponding class does not exist.
Article Source: http://www.cnblogs.com/wangxin-king/p/5669336.html
PHP Super Global variables, magic variables and Magic functions