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.

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?

Thanks,
Nikita

[1] This is a fatal error when interfaces or abstract methods are involved,
otherwise this is an E_STRICT error.

Reply via email to