Re: Allow dropping typehints during inheritance

From: Date: Wed, 04 Feb 2015 18:54:20 +0000
Subject: Re: Allow dropping typehints during inheritance
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-81835@lists.php.net to get a copy of this message
Hi Nikita, > On 4 Feb 2015, at 18:49, Nikita Popov <nikita.ppv@gmail.com> wrote: > > 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. > > This is an issue, because it makes it impossible to add typehints to > parameters at a later point in time. I've seen this issue come up both in > userland code, as well as in a recent DateTime change, see > > https://github.com/php/php-src/commit/8e19705a93d785cd1ff8ba3a69699b00169fea47 > . > > Instead of reverting the DateTime BC break, I'm wondering if it wouldn't be > better to fix the root cause by making the inheritance check less strict > and allow removing typehints? Sounds sensible to me. Of course, the reverse is true for return types, which should be either covariant or invariant. :) -- Andrea Faulds http://ajf.me/

« previous php.internals (#81835) next »