Re: Using child classes/interfaces as desired type hints
| From: | Ferenc Kovacs | Date: | Thu, 07 Oct 2010 07:24:56 +0000 |
| Subject: | Re: Using child classes/interfaces as desired type hints | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-49882@lists.php.net to get a copy of this message | ||
On Thu, Oct 7, 2010 at 7:56 AM, Nathan Nobbe <quickshiftin@gmail.com> wrote:
> Hi,
>
> Probly rehashing an old conversation here, but I'm wondering why the
> following isn't supported
>
> <?php
> abstract class AbstractServer {}
> class ConcreteServer extends AbstractServer {}
>
> abstract class AbstractClient {
> abstract function doStuff(AbstractServer $o);
> }
>
> class ConcreteClient extends AbstractClient {
> function doStuff(ConcreteServer $o) {}
> }
> ?>
>
> This results in a fatal
> Fatal error: Declaration of ConcreteClient::doStuff() must be compatible
> with that of AbstractClient::doStuff() in
> /Users/quickshiftin/gitRepos/timberline/php-api-v15-client/testOverride.php
> on line 11
>
> I was reading a few posts from way back when
>
> http://marc.info/?t=107774904800001&r=1&w=2
>
> yet still find myself wondering. I think it can be said here that if
> there's a contract defined by AbstractClient::doStuff, that same contract
> is
> honored by ConcreteClient::doStuff. I also think changing the language to
> support this notion wouldn't raise BC issues for the most part (at all?)
> since at the moment you're forced to move to the lowest common denominator
> in the tree, in this case
>
> class ConcreteClient extends AbstractClient {
> function doStuff(AbstractServer $o) {}
> }
>
> your feedback appreciated,
>
> -nathan
>
It was discussed recently:
http://marc.info/?l=php-internals&m=128220433328115&w=2
Tyrael