Polymorphism

Polymorphism is a fundamental concept in object-oriented programming (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.

<?php

class Object {}

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 ), Polymorphism in PHP, Polymorphism in PHP With Example