Php magic methods and magic constants when we learn objects, we often hear teachers say that everything in the world is an object, so we will certainly hear concepts such as magic methods and magic constants, we will summarize the following points when studying the course:
What are common magic methods in php?
1) all magic methods start with _ double underscores!
For example:
_ Construct ();
_ Destruct ();
_ Clone ();
_ Sleep ();
_ Wakeup ();
_ Get ()
_ Set ();
_ Isset ();
_ Unset ();
_ Call ();
_ CallStatic ()
Note: maybe you may say that _ starts with a magic method? _ Autoload () is available in every class, so I think it is a magic function for the time being! Hope experts can add
2)
_ Invoke (): When an object is called as a function, the magic method of _ invoke () of this object is automatically called! The called object is actually the _ invoke () method of the called object. Prerequisite _ invoke () must exist!
It can be associated with an anonymous function, that is, a closure function! Think about dynamic functions, and $ object = new A; $ object ['A']?
3) _ tostring,
This method is called when an object is used as a string. The return value of this method is the result of converting an object into a string!
Common usage: used in combination with sequence words
Let's talk about the magic constant:
_ Class0000.w.method0000.0000file __, _ LINE __, _ DIR __, _ FUNCTION _ (the name of the FUNCTION). you can refer to the manual.