Re: Allow dropping typehints during inheritance
| From: | Hannes Magnusson | Date: | Wed, 04 Feb 2015 23:58:06 +0000 |
| Subject: | Re: Allow dropping typehints during inheritance | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-81846@lists.php.net to get a copy of this message | ||
On Wed, Feb 4, 2015 at 10:49 AM, Nikita Popov <nikita.ppv@gmail.com> wrote:
> Hi internals!
>
> Currently we do not allow [1] removing a typehint during inheritance. For
> example the following code is not valid:
>
> interface A {
> public function method(Typehint $param);
> }
> class B implements A {
> public function method($param);
> }
> // Fatal error: Declaration of B::method() must be compatible with
> A::method(Typehint $param)
>
> The above code does *not* constitute an LSP violation, because B::method()
> accepts more inputs than A::method(). However we still forbid it.
So what it supports "more inputs"?
It does constitute an LSP violation. "more inputs" is not what the
guarantee is at all, if that is what you want you'd typehint on a
interface.
It is a LSP failure to allow a string, or any other scalar value, when
the parent requires a specific type/object.
It sucks that we fail our arginfo very frequently, but this is the way it is :]
-Hannes