Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Polymorphism in php

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 134
    Comment on it

    Hello Readers

    If we break the word Polymorphism poly means many (Poly = many) and morph means change ( Morph = change or form).

    Its basically the concept of object oriented programming (OOPS) in which classes have differernt functionality and use a common interface.

    or its a concept in OOPs which allows the programmers to know what they must know.

    Its a feature or characteristic in OOPs that helps the developers to make our code to be more flexible, easier to maintain, and more dynamic in nature.

    With the use of polymorphism you can provide any instance of a given base class and run the time interpreter to determine the concrete implemantation.

    Lets look the example of polymorphism:

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

    OUTPUT:

    DerivedClass

    In the above example we can use two class one is BaseClass and the other is DerivedClass,so in this object $c of class DerivedClass is executed.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: