Polymorphism Principle

Polymorphism is one of the 4 main OOP principles. It's the ability to take many forms.

Runtime Polymorphism

Runtime Polymorphism occurs in function overriding .

This means that the base class has a function that's being overwritten in the children classes:

Output:

The function calcArea in Figure class is overwritten by Square and Triangle classes.

Compile-Time Polymorphism

Unlike statically typed languages (C++, Java, C# and others), there is no such thing as compile-time polymorphism in PHP.