A brief discussion about Polymorphism in PHP

In this blog, we will discuss the polymorphism in PHP.A brief discussion about Polymorphism in PHP

This word is can from the Greek words poly and morphism. Poly means “many” and morphism means property which helps us to assign more than one property. => Overloading Same method name with a different signature, since PHP doesn’t support method overloading concept => Overriding When same methods defined in parents and child class with same signature i.e know as method overriding.

<?php

class parent
{
    function addition($a, $b)
    {
        $result = $a * $b;

        echo "Multiplication = " . $result;
    }
}

class child extends parent
{
    function addition($a, $b)
    {
        $result = $a + $b;

        echo "Addition  = " . $result;
    }
}

$obj = new child();

$obj->addition(2000, 1000);

?>

OUTPUT : Addtion = 3000

So, thanks for following this blog, and if you need any help please leave your queries in the comment box we will be happy to help you.

A brief discussion about Polymorphism in PHPexpoundsofttechsolution To remove Whitespaces from String in Python?