Re: [RFC] [Discussion] Never parameters

From: Date: Fri, 28 Mar 2025 11:28:43 +0000
Subject: Re: [RFC] [Discussion] Never parameters
References: 1 2 3 4 5 6 7 8  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
Hi

Am 2025-03-25 21:42, schrieb Rowan Tommins [IMSoP]:
And I've seen plenty of junior devs struggle with simple things like the difference between "nullable" and "optional", so I worry that making the type system too rich will lose PHP its reputation as an approachable language. It's possible I'd react less strongly if a keyword was chosen that made more sense in context, although I'm not sure what that would be.
FWIW: There is precedent for “never” as a parameter type in TypeScript. In fact, the Comparable example I gave also works in TypeScript in an unmodified fashion: https://www.typescriptlang.org/play/?#code/JYOwLgpgTgZghgYwgAgMIHsC2AHOU4BGANigN4BQyVyCWuUEAKugBTpgAW0AXMiBADdoASl4gArpgLRyAX3LkEROAGcVyALIBPAHKTpUZMBwlMEcOow48hEsgrUadPE1bsuUXtr1SRY-dD2lI7UwDDIbJyBADzInMAqwkEhKcgMYOJQIMgAtACMwSmyyBBEKihhEe6BAHxxHAlJDqmO6ZnZBS3FpeXJLdRtWcgADIUh8o7y8uQw4iAIYMDo2TDorAi8VvS2EAA0yAAmm874xBBNY7QgKugkAHRE6ADmLAh3tNYMzCwHyKp8ghEwjkQA The compareTo() method is indeed not callable OOTB and I need to tell the compiler that I know what I'm doing by the as never assertion, but it still guarantees me that the return value is a number. I also expect folks to rarely encounter never as a parameter type in practice since generic interfaces are comparatively rare, but in the cases where you have a generic interface, never feels more useful to have than not having it. Best regards Tim Düsterhus

Thread (33 messages)

« previous php.internals (#126968) next »