Polymorphism in PHP
In this tutorial, we are going to learn about Polymorphism (Greek for "many forms") a naming convention that can help us write code which is much more coherent and easy to use. According to the Polymorphism principle, methods in different classes that do similar things should have the same name.
According to the Polymorphism principle, methods in different classes that do similar things should have the same name.
A prime example is of classes that represent geometric shapes (such as rectangles, circles and octagons) that are different from each other in the number of ribs and in the formula that calculates their area, but they all have in common an area that can be calculated by a method. The polymorphism principle says that, in this case, all the methods that calculate the area (and it doesn't matter for which shape or class) would have the same name.
For example, we can call the method that calculates the area calcArea() and decide that we put, in each class that represents a shape, a method with this name that calculates the area according to the shape. Now, whenever we would want to calculate the area for the different shapes, we would call a method with the name of calcArea() without having to pay too much attention to the technicalities of how to actually calculate the area for the different shapes. The only thing that we would need to know is the name of the method that calculates the area.