Re: Why is polymorphism in PHP not like other languages? Is there a bug in PHP? [message #185045 is a reply to message #185027] |
Tue, 25 February 2014 02:43 |
Robert Heller
Messages: 60 Registered: December 2010
Karma:
|
Member |
|
|
Note a compiled language (like C++ or Java) need up-front knowledge about
things, while *intrepreted* languages defer resolving things until runtime.
Partitularly with languages where classes can be defined 'on the fly'.
At Mon, 24 Feb 2014 13:16:06 -0800 (PST) "kurtk(at)pobox(dot)com" <kurtk(at)pobox(dot)com> wrote:
>
> Evidently, PHP just works differently. Even though Quackologist::update(\Sp=
> lSubject) 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 y=
> ou get an runtime error.=20
>
> C++, on the other hand, would complain
>
> error: no member named 'whoami' in 'Base'
>
> because Base has no whoami() method.
>
--
Robert Heller -- 978-544-6933 / heller(at)deepsoft(dot)com
Deepwoods Software -- http://www.deepsoft.com/
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments
|
|
|