Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115720 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 91421 invoked from network); 14 Aug 2021 13:12:33 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 Aug 2021 13:12:33 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 47C8D1804B3 for ; Sat, 14 Aug 2021 06:44:03 -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-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (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:44:02 -0700 (PDT) Received: by mail-lf1-f48.google.com with SMTP id y34so25405111lfa.8 for ; Sat, 14 Aug 2021 06:44: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=bhFw8/lC+LcSbPDAU0KHAJovuWNGkZNsi0eOuCfSuQ4=; b=NvLc94JQvufE/XZYzPhBuY6thI6yM3/ZRE2JjwENWe60snF6ANmHiIEQn8cY0Frr0H 6hiv6+7h7eQZ+imume+AzkUtQgKLrKQizbhTxLh5Cz8tOa+uyJOtqOJDOn1npGamGHVq enDU6lIvtto94XvXpXKaf4leTjboHefH5g+w4pULVSLruW3rB6LeCW9Qdrx4M2ZVDdX8 8UVjSBbbL+qxN6FYFZAqD3rFvugmbCgBc7maENvHFFvnk96jULN0LuY9yG60mBKU0ITj wjIHe+JuydmEEFgsCb8qXPXPMGMX6oOO28fPSpowEWvzj2t52C5sZuw1MsOiUG+FgXQs 4IzQ== 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=bhFw8/lC+LcSbPDAU0KHAJovuWNGkZNsi0eOuCfSuQ4=; b=fucg1+tkLIrzcTTC2EIeNejKIxCB7uPLxWloddaE7GkPJZ5yW0TQkFvu/0pwNKj6QA CsrcPp2SsavmF2ayI6kz44BU/39So4rF95BZLfM4X4/1njmhA+uGzqni8q+ei8Fosybb 2uy3NodnK81jwUxwj5ZSd/iNVXcwCiA49MSa7ECKyqEMJIVWb9tDimWe+1vbJqlAcjQ5 1v7HaIyVCm650nuFeGwJyL9aAFE/QoyozioI4NQZONGmfk7wxTmGCDChsiHWr6UGLgfN 8EPdkgAmIgtuzEOxLGSlruY7Cq5s1gl0UiQ4wPWwdBYFiiCAu2thmqalx+xNb4mIEkFb JesQ== X-Gm-Message-State: AOAM530VtnQsDTr/cldzldFzPqJmUQEdO4C34Q4zbkY/ZvttNpsWrNUy c9bK24KdJmTHnUvaq2syU7h46fqtYveuiqL8rWI= X-Google-Smtp-Source: ABdhPJzecpsqtFRHh+vwNbYfRt22H2wuUuSiYsTthJ4cJid4OrvyvHDbYDqBnjwzYrs4dNq+Wjr+iga9s/3lhlf6nSY= X-Received: by 2002:a05:6512:4ce:: with SMTP id w14mr5060022lfq.564.1628948640135; Sat, 14 Aug 2021 06:44:00 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 14 Aug 2021 06:43:55 -0700 Message-ID: To: Nikita Popov Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000000d7d8805c98529f4" Subject: Re: [PHP-DEV] [RFC] Never For Argument Types From: jordan.ledoux@gmail.com (Jordan LeDoux) --0000000000000d7d8805c98529f4 Content-Type: text/plain; charset="UTF-8" On Sat, Aug 14, 2021 at 6:25 AM Nikita Popov wrote: > > function addMultiple(CollectionInterface $collection, mixed ...$inputs): > void { > foreach ($inputs as $input) $collection->add($input); > } > > A static analyzer should flag this CollectionInterface::add() call as > invalid, because mixed is passed to never. Effectively, this means that an > interface using never argument types cannot actually be used in anything > *but* inheritance -- so what is its purpose? > > When used as a sort of... pseudo-generics replacement, you'd need to use Docblocks to specify these, because **this feature is not generics** (which you correctly pointed out). I probably should have made that MORE clear so as to not confuse or trick anyone. If this RFC were passed, it could be sort of used like generics but it would be a bit hacky to use it that way as your example illustrates. In the absence of generics, this would probably be used as a stopgap in combination with docblocks. That's the point I was trying to make. :) The main value I see from an inheritance perspective is using never to disallow an omitted type. The inheriting class may specify *any* type, even mixed, but it must do so explicitly. Larry: > So... if I am following correctly, the idea is to allow `never` to be used in an interface/abstract method only, as a way to indicate "you must specify a type here of some kind; I don't care what, even mixed, but you have to put something". Am I following? This is essentially correct, yes, however it's important to note, and I don't want to mislead anyone here: it's not possible (to my knowledge) to *only* allow this type for parameters on interfaces and abstracts. Or at least, doing so is much, much more complicated. The patch I provided is about 5 lines different, however it allows never as a parameter type everywhere, including functions. This is, to my mind, acceptable because never will behave entirely consistently with a bottom type in all such scenarios. It will compile just fine, but if you call any function that has an argument type of never, you will get TypeError. No type which can be provided at runtime, even null, will satisfy the type never, so practically it makes a function uncallable when used as an argument type. It must be widened through inheritance to be used. Jordan --0000000000000d7d8805c98529f4--