Re: [RFC] Never For Argument Types
| From: | Ondřej Mirtes | Date: | Sun, 15 Aug 2021 08:24:53 +0000 |
| Subject: | Re: [RFC] Never For Argument Types | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-115734@lists.php.net to get a copy of this message | ||
It’s true that having “never” in a parameter type (please use “parameter”
name for the method declaration, “argument” is what you pass to a parameter
when you call the method) would allow to use any type in an overriding
method from contravariance/LSP point of view. But at the same time the
interface with the “never” parameter type isn’t useful at all, because
“never” cannot accept any type.
Same as “never” in a return type means “this function never returns”,
“never” in a parameter type means “you can never call this”.
That’s because if you have interface “Foo" with method "doFoo(never $a):
void”, you might be able to override it with “class Bar implements Foo” and
method “doFoo(A $a)”, but at the same time it only allows you to call
“Bar::doFoo(new A())”, it doesn’t allow you to call “Foo::doFoo(new A())”.
Which is probably not what people expect from a polymorphic method. So
having the method on the interface “Foo” is completely useless.
Ondřej Mirtes