Polymorphism

Polymorphism is a fundamental concept in object-oriented programming, or OOP. It allows different classes to be treated as instances of a common base class, interface, or abstract class, and it allow to write code that works with these objects without needing to know their specific types.

Polymorphism is achieved through method overriding and interfaces. It is possible to inherit from several parent classes, as long as they inherit from each other. On the other hand, implementing interfaces can be arbitrary chosen for any class and their children.

<?php

    class Object {}

    // the interfaces are empty for better readability
    interface hasMedian {}

    interface hasInscribedCircle {}

    class Triangle extends Object implements hasInscribedCircle, hasMedian {}

    class Square extends Object implements hasInscribedCircle {}

    class Pentagon extends Object {}

?>

Documentation

See also PHP Polymorphism Explained ( By Examples ) and Polymorphism in PHP With Example.

Related : Interface, Class, Inheritance, Trait, Generics, instanceof, Intersection Type, is_a(), OOP (Object Oriented Programming), Monomorphization, Existential Type, Higher-Kinded Type, Mixin, Row Polymorphism, Sealed Class, Multiple Dispatch, Pattern, Structural Typing, Type Class