When we learn objects, often hear the teachers say that the world is the object of everything, then also will hear the Magic method and magic constants and other concepts, then we learn to review the time of their own summary:
What are the common magic methods in PHP?
1) The Magic method all starts with __ double underline!
For example:
__construct ();
__destruct ();
__clone ();
__sleep ();
__wakeup ();
__get ()
__set ();
__isset ();
__unset ();
__call ();
__callstatic ()
Note: Perhaps you might say that the beginning of the __ is a magic method? __autoload () Each class can have, so I temporarily understand the magic function it! Hope the Master adds
2)
__invoke (), when an object is called as a function, the __invoke () method of the object is called automatically! Invoking an object is actually the __invoke () method that invokes the object. Prerequisite __invoke () needs to exist!
Can be associated with anonymous functions, that is, the so-called closure function! So think about dynamic functions, and $ object = new A; $object [' A ']?
3) __tostring,
When the object is used as a string, the method is called, and the return value of the method is the result of the object being converted to a string!
Common use method: use with Sequence sessions
Next, say Magic constants:
__class__.__method__.__file__, __line__, __dir__, __function__ (in the name of the function), can read the manual