Reputation: 1538
I am studying PHP and there is polymorphism example at the website i am studying at, The Link for the Code:Pastebin, What i didn't understand is why Class b and Class c after those classes that have been extended with the function hellow when they are already contain this function, i know that this is how the polymorphism works, and i am not sure but i remember some one told me that 2 functions with same name can be in one class becouse each function has it own signature, but has i say i am not sure if can some one help me to understand it please i will be very thankful.
Upvotes: 0
Views: 862
Reputation: 6172
You are not talking about polymorphism here, but very simple inheritance. Multiple methods with the same name but different signatures are indeed possible in some OOP languages (like Java), but not PHP, where method names are unique in a class.
In your case, class b
and c
hello
methods will simply replace (overload) the one already defined in a
, which they extend.
But, from your b
and c
class, you may want to call a parent class method. That's exactly what a::hello($arg1, $arg2, date('Y-M-j'));
does.
Upvotes: 2