Method overloading means using the same method name with different numbers of parameters to perform different tasks.

Method overloading allows the same method name to work with different parameters.

Method Overloading in PHP

PHP does not support method overloading compared to other languages like Java or C++. 

To overcome this issue interfaces and abstract class perform important role in PHP. 

However we can achieve this functionality by magic function like __Call()

Example Without Magic Method:

<?php
class Student {
   public function StudentName($name){
      echo "Name: ".$name;
   }
   public function StudentName($name,$age){
      echo "Name: ".$name;
      echo " Age: ".$age;
   }
}
$obj = new Student();
$obj->StudentName("Rahul");
$obj->StudentName("Rahul",20);
?>

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?

<?php
class Student {
   public function __call($name,$arguments){
      if($name == "StudentName"){
         if(count($arguments) == 1){
            echo "Name: ".$arguments[0];
         }
         if(count($arguments) == 2){
            echo "Name: ".$arguments[0];
            echo " Age: ".$arguments[1];
         }
      }
   }
}
$obj = new Student();
$obj->StudentName("Rahul");
echo "<br>";
$obj->StudentName("Rahul",20);
?>