In-depth analysis of php magic methods and magic variables, built-in methods and built-in variables. Php built-in variable: DIRECTORY_SEPARATORDIRECTORY_SEPARATOR is a php built-in command that returns the path separator related to the operating system. it is returned on windows, but in linux or un-like
Php built-in variable: DIRECTORY_SEPARATOR
DIRECTORY_SEPARATOR is a php built-in command that returns path delimiters related to the operating system. it returns/on windows, and regrets/on linux or unix-like, it is usually used when defining the path containing files or uploading and storing directories.
PHP treats all class methods starting with _ (two underscores) as magic methods. Therefore, when you define your own class methods, do not use _ as the prefix.
1. _ construct ()
When an object is instantiated, the constructor of this object will be called first;
We know that the php5 object model and the function with the same class name are class construc functions. if the construc and _ construc () methods are defined at the same time, php5 calls _ contruct () by default instead of similar name functions. Therefore, _ contruct () is the default constructor of the class;
2. _ destruct ()
The Destructor is executed when all references to an object are deleted or when the object is explicitly destroyed.
3. _ get (string $ name)
It is called when you try to read an attribute that does not exist. if you try to read an attribute that does not exist in an object, php will give an error message. If the _ get method is added to the class, and we can use this function to implement various operations similar to reflection in java.
4. _ set (string $ name, mixed $ value)
When an undefined variable is assigned a value, it is called.
5. _ call (string $ name, array $ arguments)
When an inaccessible method (such as undefined or invisible) is called, _ call () is called.
_ CallStatic (string $ name, array $ arguments)
When an inaccessible method (such as undefined or invisible) is called in a static method, _ callStatic () is called.
6. _ toString ()
This method is called when an object is printed. it is similar to the toString method of java. This function is called when the object is printed directly.
7. _ clone ()
Called when the object is cloned.
8. _ sleep ()
The serialize () function checks whether a magic method _ sleep exists. if so, the _ sleep () method is called first before the serialization operation is executed. This function can be used to clear an object and return an array containing all the variable names of the object. If this method does not return any content, NULL is serialized, resulting in an E_NOTICE error. The _ sleep method is often used to submit uncommitted data or perform similar operations. At the same time, if you have some large objects that do not need to be saved, this function is very useful.
9. _ wakeup ()
In contrast to _ sleep (), unserialize () checks whether a _ wakeup method exists. If yes, the _ wakeup method is called to prepare the object data in advance. _ Wakeup is often used in deserialization operations, such as re-establishing a database connection or performing other initialization operations.
10. _ isset ()
When isset () or empty () is an undefined variable, _ isset () is called.
11. _ unset ()
Unset an object property is called. For example, unset ($ c-> name ).
12. _ set_state ()
Called when var_export is called. Use the return value of _ set_state as the return value of var_export.
13. _ autoload ()
When instantiating an object, if the corresponding class does not exist, this method is called. In short, it is the automatic loading of classes. when you try to use a class that is not organized by PHP, it will look for a global function of _ autoload. if this function exists, PHP uses a parameter to call it. the parameter is the name of the class.
14. _ invoke ()
When you try to call an object by calling a function, the _ invoke method is automatically called.
Magic constant:
The current row number in the _ LINE _ file.
The complete path and FILE name of The _ FILE. If it is used in a file to be included, the file name to be included is returned. Since PHP 4.0.2, _ FILE _ always contains an absolute path (if it is a symbolic connection, it is an absolute path after resolution ), earlier versions sometimes contain a relative path.
The directory where the _ DIR _ file is located. If it is used in included files, the Directory of the included files is returned. It is equivalent to dirname (_ FILE __). Unless it is the root directory, the name of the directory does not include the slash at the end. (Added in PHP 5.3.0) =
_ FUNCTION name (new in PHP 4.3.0 ). Starting from PHP 5, this constant returns the name (case sensitive) when the function is defined ). In PHP 4, the value is always lowercase letters.
_ CLASS name (new in PHP 4.3.0 ). Starting from PHP 5, this constant returns the name (case sensitive) when the class is defined ). In PHP 4, the value is always lowercase letters.
_ METHOD _ class METHOD name (new PHP 5.0.0 ). Returns the name (case sensitive) when the method is defined ).
_ NAMESPACE _ name of the current NAMESPACE (case sensitive ). This constant is defined during compilation (new in PHP 5.3.0)
DIRECTORY_SEPARATOR is a php built-in command that returns path separators related to the operating system. it returns/on windows, and in linux or class un...