Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115717 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 86035 invoked from network); 14 Aug 2021 12:41:34 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 Aug 2021 12:41:34 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 71C03180088 for ; Sat, 14 Aug 2021 06:13:02 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-il1-f175.google.com (mail-il1-f175.google.com [209.85.166.175]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 14 Aug 2021 06:13:02 -0700 (PDT) Received: by mail-il1-f175.google.com with SMTP id x5so1096534ill.3 for ; Sat, 14 Aug 2021 06:13:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=crZGAKifo/jihHocSLta7i5DurA0n3v/yc/N2A7Xz7o=; b=C+9usLrQUv0Ox0o/GxlGuwOG3ZJg0GAKuYUZIcT6TzL2KttO5n8Ikt5bpBpYL45AZE cMEQ+rai4pdpJbQUTmCUNbVFoEZPm2JbhAwjMU/jJFgUBdkhCoZJtUc2RoQwDiNU0B8J 9uIyBh+xZB1gUYJo0KZ2+QWqW7Bf4rIp036TgqHX3x+YfaDpb/dbsBh7eUvdL+6WYms4 xRAyhSkTm+mCL10+ZpsjLawVxznfrfzLLl36NcgtJbQ1SD68cLFfb0+j5IXdXkErP33W f3/zaLkgM2ZivxwZnRDCog31O3jTxtMB6pfb5RKnPbAi8WRLEvpsLoEMgtbOKavUGKaP MD9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=crZGAKifo/jihHocSLta7i5DurA0n3v/yc/N2A7Xz7o=; b=HWVqOBrFVAB5lDGJ2cPAXmEfI2QQkUBOZ4ReL8hdBNPIP7d7ILVHvRxIrycJCAVi36 97HaxO3SKG9Z3CWr9d/lmmEhEEGAtrnvGD+cE3FCwusYYOh5u5plXuK48IkdGJWmbUw+ dfuwBw4O7mgBAYCwyn9fSinVBjlQNlLqpvDXN7w5rOf8E1elkOOTjeinX5cMzKCFEJyN avp/G5d1nYPn2frVu2cEqIASOygwHfS8xn4zGckx0g9wqFa2S5XghFioklZi/v1e5y+D bImXEnIFCStlUaDZyDzqEVNAa/RsQLhjEdp35i0MVb1JwEBcheRGOgQhugEQC6GHJKt1 IXxQ== X-Gm-Message-State: AOAM531qVuA+n9u3GaFgLdJdgFaAhd4A14XyiSIo62L2niAX0/eQx+ej sOmNEnWFYaYpqrjriRapw2D9eaY1Gh1wmcGjnIk= X-Google-Smtp-Source: ABdhPJwIpQfsbh8uCc4w71KWFEQ+RLOXpfaxN7wPV6xLQ8Vp2sjYNZhWbcVKxEQsww4KUMc8MFxSHoPV8tysW9Yh/VY= X-Received: by 2002:a05:6e02:6d2:: with SMTP id p18mr5199231ils.44.1628946778895; Sat, 14 Aug 2021 06:12:58 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 14 Aug 2021 15:12:46 +0200 Message-ID: To: "G. P. B." Cc: Jordan LeDoux , PHP internals Content-Type: multipart/alternative; boundary="0000000000001d384105c984baa1" Subject: Re: [PHP-DEV] [RFC] Never For Argument Types From: deleugyn@gmail.com (Deleu) --0000000000001d384105c984baa1 Content-Type: text/plain; charset="UTF-8" On Sat, Aug 14, 2021, 14:48 G. P. B. wrote: > On Sat, 14 Aug 2021 at 10:55, Deleu wrote: > >> Hi Jordan, >> >> Does it make sense to explain in the RFC the difference between never and >> mixed in this context? The RFC vaguely mentions that never can never be >> used directly, but if it's limited to abstract class and interfaces, isn't >> that already impossible to use directly? Or does it mean that the type >> would "be allowed" on any function, but because of its intrinsic behavior >> it would always fail if used in non-abstract methods? >> >> Another clarification I'd be interested is about dropping the type >> declaration entirely (e.g. https://3v4l.org/a4bfs), because of covariance >> (or contravariance, I never know), sub classes can completely drop type >> declaration entirely. Will never not allow this? Why? Why not? If it does >> allow this, does it really differ from not having any type declaration on >> the abstract function? >> >> My knowledge in this area is practically null so if I'm asking stupid >> questions that are easily explained by some blog post I'd he happy to read >> it. >> > > never and mixed are on opposite sides of the type hierarchy. > mixed is the top type, meaning it's the supertype of any other types, and > any other type is a subtype of mixed (excluding void which is not really a > "type" if you look at it, from my understanding, in a type theory way). > never on the other side is the bottom type, meaning it's the subtype of > any other type, and any other type is a supertype of never. > Finally a lack of type declaration is treated as mixed. > > Liskov's substitutions rules dictate that return types are co-variant i.e. > more specific, and argument types are contra-variant i.e. more general. > This is why any return type can be replaced by never and any argument type > can have it's type dropped/changed to mixed. > As such replacing never by mixed in an argument is totally possible as > mixed is a wider type than never. > This was incredibly useful, thank you very much. The essence that I took away is that if I declare mixed on my interface, then making it more specific (co-variant) is impossible e.g. ``` interface A { public function t(mixed $t); } interface B extends A { public function t(A $t); } ``` This is where never, being a bottom type, shines. I guess the bike shed of this one is the awkwardness of declaring an input as `never` but I'd imagine we'll either get used to it or use a possible future type alias to do `type something = never`. I guess the best aliases would be any or something, but given the interesting use case I don't think it's worth to reject this RFC solely based on how awkward `never $var` is. TL;DR thank you and I like it. > --0000000000001d384105c984baa1--