Re: Why is polymorphism in PHP not like other languages? Is there a bug in PHP? [message #185027 is a reply to message #185026] |
Mon, 24 February 2014 21:16 |
kurtk(at)pobox(dot)com
Messages: 10 Registered: May 2012
Karma:
|
Junior Member |
|
|
Evidently, PHP just works differently. Even though Quackologist::update(\SplSubject) takes a reference to \SplSubject, this fine provide you pass (at runtime) a class derived from SplSubject that implements whoami(). Only if were to pass an SplSubject instance that does not implement whoami() will you get an runtime error.
C++, on the other hand, would complain
error: no member named 'whoami' in 'Base'
because Base has no whoami() method.
|
|
|