Intercepting Calls to Object Properties and Methods

PHP 5 introduces three built-in methods that you can use to trap messages to your objects and alter default behavior.

Usually, if an undefined method is called, a fatal error will be generated and your script will fail. If you define a __call() method in your class, however, you can catch the message and decide what to do with it. Every time an undeclared method is called on your object, the __call() method will be invoked. Two arguments will automatically be populated for you: a string variable holding the name of the method that was called and an array variable holding any arguments that were passed. Anything you return from __call() is returned to the client code as if the undefined method ...

Get Sams Teach Yourself PHP in 24 Hours, Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.