Polymorphism in PHP

Advertisements

Encapsulation in PHP Inheritance in PHP

Polymorphism in PHP

Polymorphism represent more than one form, it is most, it achieve using method overloading and method overriding. This is an object oriented concept where same function can be used for different purposes. For example function name will remain same but it make take different number of arguments and can do different task.

Syntax

<?php

class BaseClass 
{ 
  public function myMethod() 
 { 
 echo "BaseClass method called";
 }
}  
 class DerivedClass extends BaseClass 
 {
  public function myMethod() 
 {
  echo "DerivedClass method called"; 
 }
} 
 function processClass(BaseClass $c) 
 {
  $c->myMethod(); 
 } 
 $c = new DerivedClass(); 
 processClass($c);

?>

Output

DerivedClass method called

Encapsulation in PHP Inheritance in PHP

Advertisements

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 8076671483

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

Download Projects