Home arrow PHP arrow Implementing Property Overloading in PHP 4

Implementing Property Overloading in PHP 4

The object-oriented paradigm includes the ability to overload classes; not surprisingly, this is possible in PHP. In this first part of a series, you will learn how to implement class overloading in PHP 4, specifically using the “overload()” function, which comes in handy for triggering “__set()” and “__get()” methods when a property access is overloaded.

  1. Implementing Property Overloading in PHP 4
  2. Overloading a property access: using the “__set()” method
  3. Overloading a PHP 4 class: using the native “overload()” function
  4. Going deeper into property access overloading: using the “__get()” method
By: Alejandro Gervasio
Rating: starstarstarstarstar / 7
July 11, 2006

print this article




If you’ve been working with object-oriented programming in PHP for a considerable time, you probably have a decent grounding in building up classes, defining their methods and properties, as well as implementing several types of object interaction, including aggregation and composition in cases where these techniques are applicable. Additionally, you’ll surely have started using some of the most important foundations of object-based development, such as inheritance and polymorphism.

To return to mastering all the concepts that I deployed before, perhaps you consider yourself an experienced PHP developer that has explored and understood the nitty-gritty of working with objects during the development of different applications. However, luckily for you and me, the object-oriented paradigm always has some additional exciting aspects that might be pretty interesting to expand our overall knowledge of PHP.

That’s precisely the case with the overloading of classes, since PHP comes with a fairly handy support for overloading both method calls and property access of objects, something that can be truly useful when used in a clever way. Certainly, I don't mean that the implementation of class overloading in PHP is as powerful as you’ll find if you work with C++ or Python, but it definitely can help in the development of more robust code, particularly when you want to combine it with the advantages offered by inheritance.

After introducing the topic, allow me to tell you what you’ll learn during the course of this series, so you won’t suffer the effects of unexpected surprises. In these articles, I’ll explain the basics of class overloading, starting with the application of the “overload()” function in PHP 4, in conjunction with using the “_set()”, __get()” and “__call()” methods, accompanied of several practical examples, so you’ll have a clear idea of how to overload your classes. Also, I’ll cover class overloading in PHP 5, which offers native support for overloading methods and properties through the built-in methods that I mentioned before.

With the preliminaries out of our way, let’s start learning more about how to implement class overloading in PHP. Let’s go!

>>> More PHP Articles          >>> More By Alejandro Gervasio

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: