Hi Nikita, > On 4 Feb 2015, at 18:49, Nikita Popov <nikita....@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/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php