Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126702 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 F0F061A00BC for ; Mon, 10 Mar 2025 22:11:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1741644547; bh=7X2hiQf5AmsM0l4h7Y+AlIyDG6Qp8oVADvFPbIf1SpI=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=NaPmzmoBUM9Pe2r/Wlmrp1j9Vgn83MSu92RCK441U0z7h/BhdYP5utSICiFRLNMPs Vq/u8eXJN+NHpGEuGyrRUxFWwQnocmbK3c5rtVScTaC8dZLfswTsNEz9tMX3WcEh+C IxCN02NGOlDOCE9cxYx/W6MOBs7ZnTExUXEQEk2L5x8Io+5/Yc93bwvHuhNXxvgyp9 /HOsM0L7fIOqHpgOTh8MRD83E13Pon5ocXQQQvTMqv//j+8luPXK2lkpzoOQrXzkyF 5+cXPbckZe1ZpAuznMz9Q46HCCT2WEujIkB5B2k11HepRlZRl4uRMn/1R0inmvLzK+ wmXVrh3Wm6H5g== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9E4EE180034 for ; Mon, 10 Mar 2025 22:09:06 +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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from nebula.zort.net (nebula.zort.net [96.241.205.3]) (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 ; Mon, 10 Mar 2025 22:09:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=zort.net; s=zort; t=1741644700; bh=7X2hiQf5AmsM0l4h7Y+AlIyDG6Qp8oVADvFPbIf1SpI=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=WFQM0MV+eiB+PHgm8nekI4SVMwGX8iepo8IEZC8PtW1zt1F1lGy6ANckYOMnyotWu H9gKQzGLr9SEIeKQSY3WYQLttitErAwS6WVGas4FxdpeWBlegWVBMAODTA8xMd9h6F mPT0+XYiGf6/G22U92hkrPtMOerpIssmSFYgTpuk= Received: from smtpclient.apple (unknown [49.227.173.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by nebula.zort.net (Postfix) with ESMTPSA id 4D83A13004AF; Mon, 10 Mar 2025 18:11:39 -0400 (EDT) Content-Type: text/plain; charset=us-ascii Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.400.131.1.6\)) Subject: Re: [PHP-DEV] [RFC] [Discussion] Never parameters In-Reply-To: Date: Tue, 11 Mar 2025 11:11:25 +1300 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: <934418CE-579E-4621-BB7A-5332B87C27B2@zort.net> References: To: Daniel Scherzer X-Mailer: Apple Mail (2.3826.400.131.1.6) From: jbafford@zort.net (John Bafford) Hi Daniel, > On Mar 11, 2025, at 08:05, Daniel Scherzer = wrote: >=20 > Hi internals, >=20 > I'd like to start discussion on a new RFC about allowing `never` for = parameter types when declaring a method. >=20 > * RFC: https://wiki.php.net/rfc/never-parameters-v2 > * Implementation: https://github.com/php/php-src/pull/18016 >=20 > -Daniel The RFC says that: > never can be used as a parameter type, subject to the following = restrictions >=20 > * it cannot be used in the declaration of any method that has an = implementation. Methods with never can never (pun intended) be called, = because there are no values that satisfy the type constraint. Instead of = delaying the error until runtime when the user attempts to call the = method, just require that the method not have a body. I would point out that `never` can be conceptually represented as a = caseless enum. Right now, code like this is valid (as in, does not = produce errors, though in practice, it's also not callable): > enum Never {} > function foo(Never $never) { echo "wat"; } > function bar(Never $never) { foo($never); } If we're going to deny the use of `never` as a parameter to a function = with a body (even an empty body), perhaps we should also consider the = caseless enum case. For the sake of consistency, we might want to deny = use of caseless enums as function parameters. Alternatively, we might = want to explicitly allow that use case to allow for a "I know I'm going = to have cases here, but I don't know what they will be, but I'm still = going to write some functional code around this first and would very = much like my code to compile even though I haven't actually added any = cases yet." scenario. Which I have definitely done before. Either way, = it's an inconsistency worth clarifying. This is a bit future-gazing, but, when considered in the context of = generics, it's normal and useful to have class members and bodied = functions with (generically) never types. You might see this, for = example, with a Result type, where Failure =3D=3D = Never. We would want to allow those use-cases, and disallowing it for = non-generic functions would be an inconsistency. -John