PHP-manual | ||
---|---|---|
Föregående | Kapitel 19. Classes and Objects (PHP 5) | Nästa |
Both method calls and member accesses can be overloaded via the __call, __get and __set methods. These methods will only be triggered when your object or inherited object doesn't contain the member or method you're trying to access. All overloading methods must be defined as public.
Class members can be overloaded to run custom code defined in your class by defining these specially named methods. The $name parameter used is the name of the variable that should be set or retrieved. The __set() method's $value parameter specifies the value that the object should set the $name.
Class methods can be overloaded to run custom code defined in your class by defining this specially named method. The $name parameter used is the name as the function name that was requested to be used. The arguments that were passed in the function will be defined as an array in the $arguments parameter. The value returned from the __call() method will be returned to the caller of the method.
Exempel 19-19. overloading with __call example
The above example will output:
|
Föregående | Hem | Nästa |
Object Interfaces | Upp | Object Iteration |