Overloading in Oops

In this tutorial, you will learn the method overloading, in PHP Overloading and Overriding are forms of polymorphism in OOP. According to Overloading Concept, Two or more methods have the same name but different parameters.



It is also called static polymorphism, compile-time, and Early binding polymorphism.

Method Overloading: When multiple methods exist within the same class with the same name but different in signatures.

Method Overloading in PHP

PHP does not support method overloading compared to other languages like Java or C++. To overcome this functionality interfaces and abstract class plays important role in PHP. However we can achieve this functionality by magic function like __Call()

Why Method Overloading is an Advantage in Oops



  1. Overloading is used when you want to extend the functionality.
  2. Overloading is known as compile time polymorphism

Examples of Method Overloading

But, In PHP this will throw fatal Error. Incase of C++, and Java it will work fine. To overcome this we can use __Call().

How to Use __Call() to achieve this?

 



Tags: , , ,