loading...

How To Implement Polymorphism In PHP?

pakainfocom profile image pakainfo ・1 min read

In PHP Polymorphism represent an example in OOP means object-oriented programming where methods in different types of the classes that do equivalent things should have a equivalent name.

How To Implement Polymorphism In PHP?

Poly meaning => many
morphism meaning forms
There are main two types of Polymorphism in PHP like as a

polymorphism in Compile time (function overloading)
polymorphism in Run time (function overriding)

This word is can from mainly use of the Greek word poly and morphism. Poly stands lots of or “many” as well as morphism stands some property which uses us to give more than one property. like as a concept of the => Overloading Same PHP method name with different signature type, since PHP doesn’t support PHP method Data overloading concept like as a => Overriding When same methods defined in main as well as sub class with same data signature Example as a know as PHP method overriding

  
class Module  
{  
    function produce(){}  
}  

class Product extends Module  
{  
function produce()  
    {  
    print "Product has been generated.";  
    }  
}  

class Brand extends Module  
{  
    function produce()  
    {  
     print "Brand has been generated.";  
    }  
}  

class Category extends Module  
{  
    function produce()  
    {  
        print "Category has been generated.";  
    }  
}  
   
$results=array(2);  
  
$results[0]=new Product();  
$results[1]=new Brand();  
$results[2]=new Category();  
  
for($i=0;$i<3;$i++)  
{  
    $results[$i]->produce();  
}  
?>  

You can step by step learn to full Article Polymorphism In PHP

Posted on by:

pakainfocom profile

pakainfo

@pakainfocom

My name is Angular King. I'm a full-stack developer, entrepreneur and owner of Pakainfo. I live in India and I love to write

Discussion

pic
Editor guide