PHP provides built-in interceptor methods (also called magic methods), which are automatically executed in some special cases, when are accessed undefined methods and properties.
- Magic methods must be defined with "public" attribute.
__get(), __set() and __call() methods:
The __get() and __set() methods are generally used together and are designed for working with properties that are not defined in a class (or its parents).
__get($property) - automatically invoked when an undefined property is accessed
__set($property, $value) - automatically invoked when a value is assigned to an undefined property
The __get() method must be defned with one parameter
The __set() must be declared with two arguments.
The __call() method is invoked when an undefined method is called. It must be defined with the following sintax: