This is part two of the series “Overloading classes in PHP.” In three tutorials, this series teaches how to overload your classes in PHP 4 by using the “overload()” PHP built-in function, in conjunction with the implementation of the “__set()”, “__get()” and “__call()” methods, and explores the native support of object overloading in PHP 5.
As usual, I’d like to refresh the topics that I covered in the first part of this series, regarding the overloading of classes in PHP 4, so it will be much easier to come back to the subject and continue exploring its most relevant aspects. Stepping back to the previous tutorial, you’ll certainly remember that I went through the key points of overloading classes in PHP, and paid close attention to explaining the implementation of the “__set()” and “__get()” methods, which can be called automatically, after a given class has been overloaded.
Particularly, I showed you how to trigger the methods by overloading several property accesses. This can be quite useful, particularly if you want to run custom code without the need to explicitly call these methods. As you learned before, after a class has been overloaded by the “overload()” function, the PHP 4 interpreter will enable this functionality, which can be used in different clever ways.
All right, after refreshing the concepts that I covered in the previous tutorial, it’s time to focus on the current one. In this second article, I’ll first show you how to combine the two “__set()” and “__get()” methods into one single class, so they can be properly triggered when overloading a property access. Then I’ll teach you how to overload a method call, in order to trigger the homonymous “__call()” method.
After defining the topics to be covered in this second article, let’s move on and continue exploring the different approaches for overloading classes in PHP 4. It’s going to be really instructive!