According to the PHP documentation:
The overload() function will enable property and method call overloading for a class identified by class_name.
http://www.php.net/manual/en/function.overload.php
But what does that mean exactly? Does it mean I can do proper overloading on that class (like Java's overloading)?
Overloading ¶ Overloading in PHP provides means to dynamically create properties and methods. These dynamic entities are processed via magic methods one can establish in a class for various action types.
Using the function overloading concept, we can develop more than one function with the same name, but the arguments passed should be of different types. Function overloading executes the program faster. Function overloading is used for code reusability and to save memory.
PHP does not support method overloading. In case you've never heard of method overloading, it means that the language can pick a method based on which parameters you're using to call it. This is possible in many other programming languages like Java, C++.
The main advantage of function overloading is that it improves code readability and allows code reusability. The use of function overloading is to save memory space, consistency, and readability. It speeds up the execution of the program. Code maintenance also becomes easy.
It basically enables the magic accessor methods such as __get()
, __set()
, etc.
Since PHP5 this is no longer necessary and enabled by default. In fact, you can't switch it off ;-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With