First, the Magic function(13)
1, __construct ()
Called when an object is instantiated, and when __construct and a function with the name of the class name are present, __construct is called and the other is not called.
2, __destruct ()
Called when an object is deleted or when an object operation terminates.
3, __call ()
The object calls a method, and if the method exists, it is called directly; if it does not exist, it will call the __call function.
4, __get ()
When a property of an object is read, the property value is returned directly if the property exists, or the __get function is called if it does not exist.
5, __set ()
When a property of an object is set, the value is directly assigned if the attribute exists;
If it does not exist, the __set function is called.
6, __tostring ()
Called when an object is printed. such as Echo $obj; or print $obj;
7, __clone ()
Called when the object is cloned. such as: $t =new Test (); $t 1=clone $t;
8, __sleep ()
Serialize before being called. If the object is relatively large, want to cut a bit of the east and then serialize, you can consider this function.
9, __wakeup ()
Unserialize is called to do some initialization of the object.
10, __isset ()
Called when detecting whether an object's properties exist. such as: Isset ($c->name).
11, __unset ()
Called when a property of an object is unset. such as: unset ($c->name).
12, __set_state ()
Called when the Var_export is called. Use the return value of __set_state as the return value of Var_export.
13, __autoload ()
When an object is instantiated, the method is called if the corresponding class does not exist.
second, the magic constant(8)
1, __line__
Returns the current line number in the file.
2, __file__
Returns the full path and file name of the file. If used in the include file, the include filename is returned. Since PHP 4.0.2, __file__ always contains an absolute path, and the previous version sometimes contains a relative path. 3, __dir__
The directory where the file resides. If used in the included file, returns the directory where the included files are located. It is equivalent to DirName (__file__). Unless it is a root directory, the name in the directory does not include the trailing slash. (New in PHP 5.3.0)
4, __function__
Returns the name of the function (PHP 4.3.0 new addition). From PHP 5 This constant returns the name (case-sensitive) when the function is defined. In PHP 4, this value is always in lowercase letters.
5, __class__
Returns the name of the class (PHP 4.3.0 new addition). From PHP 5 This constant returns the name of the class when it is defined (case-sensitive). In PHP 4, this value is always in lowercase letters. 6, __trait__
Trait's name (PHP 5.4.0 new Plus). From PHP 5.4 This constant returns the name of the trait when it is defined (case-sensitive). The Trait name includes its declared function area (for example, Foo\bar).
7, __method__
Returns the method name of the class (PHP 5.0.0 new). Returns the name of the method when it is defined (case-sensitive). Format: Class Name:: Method name 8, __namespace__
The name of the current namespace (case-sensitive). This constant is defined at compile time (PHP 5.3.0 new)
three, predefined constants
Php_version versions of PHP programs, such as 4.0.2
Php_os the name of the operating system that executes the PHP interpreter, such as Windows
Php_sapi is used to determine whether it is executed using the command line or the browser, if the php_sapi== ' CLI ' indicates that it is executed at the command line
E_error the most recent error
E_warning, the nearest warning point.
E_parse Anatomy Grammar has a potential problem
E_notice is unusual, but not necessarily the wrong place.
Php_eol System line break, Windows is (\ r \ n), Linux is (/n), Mac is (\ r), from PHP 4.3.10 and PHP 5.0.2 Available
Directory_separator system directory delimiter, Windows is backslash (\), Linux is slash (/)
Path_separator inter-Path delimiter, Windows is backslash (;), Linux is slash (:)
Php_int_max INT Maximum, 32-bit platform value 2147483647, from PHP 4.4.0 and PHP 5.0.5 Available
Php_int_size INT Word length, 32-bit platform value is 4 (4 bytes), since PHP 4.4.0 and PHP 5.0.5 Available
PHP Magic Functions, Magic constants, pre-defined constants