Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126972 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 35EAE1A00BC for ; Sat, 29 Mar 2025 02:46:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1743216257; bh=cHBzPCEkDdiXtRLA7eHnO36Bqf1FqKZdGtdEkALTsD4=; h=Date:From:To:In-Reply-To:References:Subject:From; b=CRtZABG9v3MMLbwPj/ukFtxMPVXuti70Zb7TTwO7NV7KJ0b9AS9HSszIww5GVjRuq juGcqIz6sStXphSEKdA734sH/St1Bn1bWFEy33xSclo/Torf2zfDJszhWnz5/NzleF UP4mOB7LHymP9S+NmaNnPhXF6drOvzP29tWTnG1lIpuJ4ZPHgm2Gh4gIka6TN7iHzX 5fuTTM4ag1wZ9MS1yVa+BJ5XeE639f4V0a/d6oQkCT182XZMpg/kv9kschL/KWKqf/ nB6gM4IEk6NjcD1HFKtFbCWNQ817sbyym5aBCZmrJ7PPROTLXZ11Ty5Y4spj5HSuUc Dbol0cAk45ShQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4A45A180082 for ; Sat, 29 Mar 2025 02:44:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fhigh-b5-smtp.messagingengine.com (fhigh-b5-smtp.messagingengine.com [202.12.124.156]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 29 Mar 2025 02:44:16 +0000 (UTC) Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailfhigh.stl.internal (Postfix) with ESMTP id 8A29825401CD for ; Fri, 28 Mar 2025 22:46:43 -0400 (EDT) Received: from phl-imap-06 ([10.202.2.83]) by phl-compute-04.internal (MEProxy); Fri, 28 Mar 2025 22:46:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to; s=fm2; t=1743216403; x=1743302803; bh=YWTvZQfAyLeeD52tOLXeh Jjk9K3u0EeoYPJ03FnAVAA=; b=boBiRScE6e6vF0QcGP9SXssywFS7RRucW6Nnt VX0pPWNEfOjOuVLQtOsT9Hkbju1S3HrWfNxTXtQhE9JhOG2/FK3HnlLvXSqcsyMY ZbKrojd7ZGZorSlUAnmngXm33Jsv8swzJyIkNOkFMC34g/e773uGq2u1EsrLdhEC 3KL+2GWNkcqV1dwOeuSyeiKqdmUkTB1uBItnl7h7DNsMY1zj6OhohZXncI0L/Hmd 50hK5Hcnr63Yq2bqzmHF3IB4hVzom1Bp09maMicVPp/rV7Ia6KavyLEa2Q384E+0 MKYo5dbptY0CiSw0QW4QzAxxdbXNdwqEKj91KX7XMys5O1TnA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1743216403; x=1743302803; bh=Y WTvZQfAyLeeD52tOLXehJjk9K3u0EeoYPJ03FnAVAA=; b=D/WAJMgq/ZowA1w43 ASrv3MQh+0dm/JhqnAlfS5Ilb63ws9+HsFC1yy6jk2BhQ9FTPUpUI0WysHaoG0K7 phvsNfnSAUBjGTle9ilw/+BFZygRyDwSu90jrj86u7lsYiQyuxLZEjIhkEhUi/d8 X7YHs0MGLeEo6T0kBu7RrZOLKW5jN68zeuF8B8B3vk9yb4I+qx/FnisjXI5WX+/J nuKtfrNjlLl7vfodJsHByCoSt+HhcJ9fLhiKlOWVfzJSYHw7pLAtafZv2itB9+an 4+MCbWR2FPTgzHaOtog/e+cOvD8ugS3cbYDZ+3iI5+Gau+kF3Kj5Tbgyl/aIZmKQ bCanA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddujeeftddtucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnegoufhushhpvggtthffohhmrghinhculdegledmnecujfgu rhepofggfffhvffkjghfufgtgfesthhqredtredtjeenucfhrhhomhepfdfnrghrrhihuc firghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhmqeen ucggtffrrghtthgvrhhnpeehffdvteejtedvhfetgfetheefjeeiteehfefhhefgheekte ffteeujeejjefggfenucffohhmrghinhepfehvgehlrdhorhhgnecuvehluhhsthgvrhfu ihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlh guthgvtghhrdgtohhmpdhnsggprhgtphhtthhopedupdhmohguvgepshhmthhpohhuthdp rhgtphhtthhopehinhhtvghrnhgrlhhssehlihhsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 2BD5D29C006F; Fri, 28 Mar 2025 22:46:43 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 X-ThreadId: T499b434fb43e9cfc Date: Fri, 28 Mar 2025 21:45:58 -0500 To: "php internals" Message-ID: In-Reply-To: References: Subject: Re: [PHP-DEV] [RFC] [Discussion] Never parameters Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: larry@garfieldtech.com ("Larry Garfield") On Fri, Mar 28, 2025, at 3:42 PM, Matt Fonda wrote: > Hi Tim and Larry, > > Thanks for sharing examples. I'm not sure I follow how never parameter= s=20 > help in either of these cases. As far as I can tell, the problem=20 > remains that these methods can't actually be called. > I share Nikita's sentiment in the previous RFC discussion [1], and hav= e=20 > yet to see an answer to it: > >> I don't think this really addresses my concern, so let me repeat it: = You >> cannot actually call a method using a never-type argument while typing >> against the interface. What's the point of the interface then? >>=20 >> I don't think "you must use this in conjunction with a 3rd-party phpd= oc >> generics implementation for it to make any sense at all" is a suitabl= e way >> to resolve that. > > On Fri, Mar 21, 2025 at 8:53=E2=80=AFAM Larry Garfield wrote: >> Changing the interface to use `never` instead of `mixed` would have t= he weakest guarantees of the three, since it doesn't force me to use the= *same* widened type on serializeInt(), serializeFloat(), serializeStrin= g(), etc., even though it would always be the same. But it would allow = me to communicate more type information than I can now. > > Suppose you made this change from mixed to never. As long as you're=20 > typing against the Formatter interface and not a specific=20 > implementation, then you cannot actually call=20 > $formatter->serializeInt() etc. because the interface defines the=20 > parameter type as never, and you cannot call a method with a parameter=20 > type of never. > > This is the case in your real world usage [1]. Here,=20 > $serializer->formatter is typed against Formatter [2], not a specific=20 > implementation. As such, all we know is that we have an instance of=20 > Formatter--we don't know anything about the concrete type--and thus we=20 > can't actually call e.g. serializeInt() because never is the only type=20 > we know here. I have to think people are misunderstanding Nikita's earlier comment, or= perhaps that he phrased it poorly. =20 The determination of whether a method call is type-compatible with the p= arameters passed to it is made *at runtime*, on the class. You can wide= n a parameter type in an implementing class, and it will work. That's b= een the case since PHP 7.4. For example: https://3v4l.org/5YPdg Even though the function is typed against I, if it's passed a C, you can= call it with a string. That's because C::a()'s param type is wider tha= n the interface. The idea of a never typed parameter is exactly the same: It starts off s= uper-narrow (accepts nothing), so implementations can accept anything wi= der than "nothing" and still be type compatible. You *can* call it. What you cannot do is determine *statically* that it is callable, becaus= e at static-analysis time, all you know is the interface. So SA tools w= on't be able to verify that anything is valid for that interface. That'= s a valid criticism of never params, I agree. Is it enough to vote agai= nst it on those grounds? That's up to each voter to decide. But "you cannot ever even call it" is simply not true, unless there's so= me weird engine limitation that I don't know about. In fairness, though, it seems to me that Associated Types would have the= same SA issue. It would probably be more evident for them that they ca= nnot try to enforce the type statically, but I don't know how they could= do a better job of reporting it than with a never type. (Someone else = who understands Associated Types better than I, how would that work?) --Larry Garfield