Polymorphism is a concept in which a class containg more than one method with the same name but behaviour of each method is different is called polymorphism.

There are two types of polymorphism.

  1. Compile-time polymorphism or  method overloading  or static polymorphism or early binding
  2. Run-time polymorphism  or method overriding or Dynamic polymorphism or late binding or dynamic binding
S.No.Compile-time polymorphism or  method overloadingRun-time polymorphism  or method overriding
1Method overloading is a mechanism in which a class contain more than one method with the same name but parameter is different is called method overloading.Method overriding means that you can redefine a base class method in a derived class. overriding is process of modifying the inherited method. So in case of inheritance you only need to create method with same name in your child class which you want to override.
2
<?php
                    function set_name($data)
                    {
                    $this->name=$data;
                    }
                    function set_name($data, $msg)
                    {
                    $this->name=$data;
                    $this->message = $msg;
                    }
                    $obj->set_name("mahtab");
                    $obj->set_name("mahtab", "alam");
                    ?>
<?php
                    class A
                    {
                    public function test($param)
                    { echo "\n Parent - the parameter value is $param";
                    }
                    }
                    class B extends A
                    {
                    public function test($param)
                    { echo "\n Child - the parameter value is $param";
                    }
                    }
                    $objA = new A;
                    $objB = new B;
                    $objA->test('class A');
                    $objB->test('class B');
                    ?>

 

OVERLOADINGOVERRIDING
It is performed at compile time.It is performed at runtime.
It is carried out within a class.It is carried out with two classes having an IS-A relationship between them.
Parameters do not remain the same in case of overloading.The parameter must remain the same in case of overriding.
You can perform overloading on static methods.You cannot perform overriding on static methods.
Overloaded methods use static binding.Overridden methods use dynamic binding.