In this tutorial, you will get a detailed concept about the method overriding in PHP with examples.
Overriding in Oops- PHP
Overriding means having two methods with the same arguments, but different implementation
Two or more methods having the same method name and same argument but in different class is known as overriding. it is also known as run time polymorphism, dynamic polymorphism, and dynamic binding.
Method Overriding Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | <?php class Online { function freeonlinetest() { echo "Parent"; } } class Test extends Online { function freeonlinetest() { echo "Child"; } } $O = new Online; $T= new Test; $O->freeonlinetest(); $T->freeonlinetest(); //Output Parent Child ?> |
But this overriding concept does not support in PHP, So implementing polymorphism, interfaces
and abstract
class play important role in PHP.