| Start |
|---|
| __call() and __callStatic()
Example: |
| __get(), __set(), __isset() and __unset() Whenever you attempt to retrieve a certain field from a class like so: PHP invokes the magic method Will invoke the magic method PHP also has two built-in functions Will invoke the Will invoke the Normally, when you don't define these methods on your class, PHP just retrieves the field as it is stored in your class. However, you can override these methods to create classes that can hold data like an array, but are usable like an object: empty() function and magic methodsNote that calling empty() is essentially the concise equivalent to !isset($var) || $var == false |
| __construct() and __destruct()
|
| __toString() Whenever an object is treated as a string, the |
| __clone()
Example: |
| __invoke() This magic method is called when user tries to invoke object as a function. Possible use cases may include some approaches like functional programming or some callbacks. |
| __sleep() and __wakeup()
|
| __debugInfo() This method is called by The above example will output: The above example will output: |
Read Article
https://develop.horje.com/learn/1434/reference