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

Google Advertisment

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

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

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements