PHP Polymorphism Function:
The PHP Polymorphism Method is one of the feature of OOP language. Generally we get polymorphism in two ways:
Compile time polymorphism PHP is like function overloading, operator overloading etc. In Polymorphism function overloading we can create more than one function with same name but with different signature that means it could have different number of parameters, different datatype of the parameter etc. Depending on the actual number and/or the data type the compiler resolve the actual call .
In operator overloading predefined operators treat as functions and one object calls this function and passes another object as argument. PHP neither supports operator overloading nor function overloading.
Inheritance and virtual functions are the examples of PHP Run time polymorphism. PHP supports Inheritance as well as virtual function as function overriding.
Following examples will exemplify each of the types of polymorphism:
PHP Polymorphism Function Example:
<?php
class
A{ function Disp(){ echo "Inside the Base class<br/>";}}class
B extends A{ function Disp(){ echo "Inside the Chlid class<br/>";}}class
C extends A{}
$obj
=new B();$obj
->Disp();$obj2
=new C();$obj2
->Disp();?>
Output:
Inside the Chlid class
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.