Hello list,
to revive this old RFC.
One really nice application of never parameters is with intersection types:
interface I {}
interface ReturnI {
public function foo(never $x): I;
}
interface AcceptI {
public function foo(I $x): mixed;
}
function f(ReturnI&AcceptI $arg, I $x): I {
return $arg->foo($x);
}
Look at a live example where I simulate the "never" with an
"AlmostNever" interface.
It can even be applied with additional parameters:
An application can use this to reduce the range of individual
interfaces, and cover scenarios that would otherwise require generics
or callable types.
So.. I would really like to see it
--- Andreas
On Sat, 14 Aug 2021 at 01:27, Jordan LeDoux <jordan.ledoux@gmail.com> wrote:
Hey internals,
I've been working on the draft for my operator overloading RFC, and in
doing so I encountered a separate change that I would like to see.That is, the use of `never` as an argument type for interfaces. Since
arguments in PHP are contravariant to preserve Liskov substitution, `never`
as the bottom type should indicate that implementing classes can require
any type combination they want. This is in fact consistent with type theory
and set theory, and is how the bottom type is treated in several other
languages.In this case, the bottom type would be used to indicate covariant parameter
polymorphism while not conflicting with LSP.This would provide a sort of minimal form of generics to PHP without the
issues that actual generics present from an implementation perspective. It
would not, however, restrict or hinder any future RFC for generics.This is at the first draft stage, and I currently have the RFC on a github
repo to allow for easy contribution and collaboration.Any feedback is greatly appreciated.
GitHub - JordanRL/never-argument-type
Jordan