Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115719 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 89164 invoked from network); 14 Aug 2021 12:54:28 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 Aug 2021 12:54:28 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 928D6180212 for ; Sat, 14 Aug 2021 06:25:55 -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-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (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:25:55 -0700 (PDT) Received: by mail-lf1-f47.google.com with SMTP id g30so25370303lfv.4 for ; Sat, 14 Aug 2021 06:25:55 -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=rjzLzfuQ8C6ox7n/GLefkn4a/Hv2WVJhtbGOnO8j8pM=; b=bMAWitpCwPrpu3xbwbxt48SKAEdZUKUXYcosMJmU4Zk9AkN0/WhIx8BU3Qja9x2aP5 pn6RJv7HNirT9RjEipMD9i2IJjCX6yUkTFsUVxrXkLRVayujKwqQQNm3Vk2Be8GBKYBe mLg3UD7Czc98nzUO6Gv28H8syRP68CdJDmSSBq/o23wKotBFLTABiX34/X1m0d3H00OJ XrkR0Xf+P4SNwlFkBR+vykAC3rb4dLE1cqPwL3EfwXou5wRmIvR4vWcjVEf+xtxIkfwb TNqTprkhcpdR/6ksNRyZqfWbzUQXPHb7CaYWKup2A/r6XPvflU6t3YIuDD4jxH+eBqC5 1U+g== 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=rjzLzfuQ8C6ox7n/GLefkn4a/Hv2WVJhtbGOnO8j8pM=; b=Dq8auzRwxqmvZ5fXwK4YA7yTjRNIjCcwKMy1t6q61PrteX7TtpH1rDz+RlyK6g9fZd Rz/W0FQfxpbDb78GhXwLgVjKWcUsv8Kw54yifL5imM3ncTdbwlZEeo2uNA1X5vXRrOLX ubCYmvy2DNu/PCAPFXioNgFnVh+LjmBo/STq0B4HzOPcLmgOX32RaIW5E4HqpvdgpUVL EMhO2NnDI89/S4TqiQZVx2w5l3oVQ029LYyOQba9Ygy1Ut3eyAQaxbc9S8a95d2Yem8H b8/XixyUBBDKak/0sokR5MvemYtoQEPM8uOlVGLe3telPs/75eKtcw3v0prHfP72ShZC WTZg== X-Gm-Message-State: AOAM5332yigVZl1tSrm0nOY+2EV/ECrkpUPgh64BV6C0vzkLVGGgpzWk AeEa+3NZE4KIK8aNp6cFXYGVub5rZZryaY8GNB4= X-Google-Smtp-Source: ABdhPJyKM8424cT63I4bPU3g0zTOXtyhQWfMbMlqBvmKy2VGI7HT/owvrz89kyZrZUGX5uZu3vruiEOvw84nTrbdCn4= X-Received: by 2002:a05:6512:3f1:: with SMTP id n17mr5425442lfq.44.1628947552591; Sat, 14 Aug 2021 06:25:52 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 14 Aug 2021 15:25:36 +0200 Message-ID: To: Jordan LeDoux Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000003ae44405c984e81c" Subject: Re: [PHP-DEV] [RFC] Never For Argument Types From: nikita.ppv@gmail.com (Nikita Popov) --0000000000003ae44405c984e81c Content-Type: text/plain; charset="UTF-8" On Sat, Aug 14, 2021 at 1:27 AM Jordan LeDoux 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. > > https://github.com/JordanRL/never-argument-type > There's two sides to this coin: While using a never argument type allows you to avoid the LSP problem, it also means that you cannot call the method while typing against the interface. Let's take your CollectionInterface interface CollectionInterface { public function add(never $input): self; } and actually try to make use of it: 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? Compare this to generics. The interface changes to interface CollectionInterface { public function add(T $input): self; } and the use changes to function addMultiple(CollectionInterface $collection, T ...$inputs): void { foreach ($inputs as $input) $collection->add($input); } Now a T argument is passed to a T parameter, and everything is fine. Regards, Nikita --0000000000003ae44405c984e81c--