Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126725 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 5E7C31A00BC for ; Wed, 12 Mar 2025 09:17:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1741770918; bh=96cQnaz1/JlAUJ71A39hXwVmacmyYBRUIw2Q4CzGmF0=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=ksdB03D1YrfiEjq4XGdtNZb3nPqFbYHqxLLqrXNoAePpIe5YmB4lGMO7ueBaPobKi 9r5gP1tSZodZWZzBfRNlKochsFsTYATpIcvrl+TXHZiNqDjGAdpl7JISsy3NcjmkEW MBNrFtnTwkMYJ8tiFSTVDFuvFGK97qwg+ugh5ZigbsC19AcUkOszN9SlZX+1pP1WxG syAeNfpCV4bW3W1NuxyWVB0Z73YE+Yd6QpGG7K/RI79izQagpq7H1c9S8mQMHDA5L5 U6GHCbO+Lu05tnnsJAoZrzVdWc+2/d32w03Wactj9D4KiROQT4mTvJkzEr0xCyG4w0 cZ30F6hblEYhw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 01152180034 for ; Wed, 12 Mar 2025 09:15:17 +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=0.0 required=5.0 tests=BAYES_05,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,HTML_MESSAGE, SPF_HELO_SOFTFAIL,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from p00-icloudmta-asmtp-us-east-1a-60-percent-11.p00-icloudmta-asmtp-vip.icloud-mail-production.svc.kube.us-east-1a.k8s.cloud.apple.com (npq-east2-cluster1-host3-snip4-2.eps.apple.com [57.103.77.5]) (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 ; Wed, 12 Mar 2025 09:15:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=garsi.de; s=sig1; bh=uNdqgiUs/CfpnbicJc64xI1zTpVzC94vc97OZxHsNsM=; h=From:Message-Id:Content-Type:Mime-Version:Subject:Date:To:x-icloud-hme; b=AvXWb07J9QZJJ5YUN9K23Z3jYqejax3f7nJRhFlryXr9vVtmBIZJmrc3vys0oJ8if byDh7ejMCR7SrteS0MRppfQ911sD/b5p4oMbK2FqJJ8szgd33EFz5zYpOSUVp6TKzp dEyOQoXWr2KrYS42S7lW9FMREFKainzJFbYs+V+cxUKq5FpsD9xjcHV3dyLr+64nLC +QuRuDbIFJbaACkfp+Usq0jW4s7vgc+XslOg9Q7KN7rKz7yxaR2NtA0bpvuYF0GIMf p3ZNyx1qW68XtI4LYeAb6RLT5F/yu7cgm0DBXkayH43x/wDW8ic5nLg1Iv8yh9lxlo eiCtoGMxrAHAA== Received: from smtpclient.apple (st-asmtp-me-k8s.p00.prod.me.com [17.42.251.67]) by p00-icloudmta-asmtp-us-east-1a-60-percent-11.p00-icloudmta-asmtp-vip.icloud-mail-production.svc.kube.us-east-1a.k8s.cloud.apple.com (Postfix) with ESMTPSA id 9264B18028ED; Wed, 12 Mar 2025 09:17:48 +0000 (UTC) Message-ID: <3C61F33E-7399-45F2-8DFD-AAC3443E519F@garsi.de> Content-Type: multipart/alternative; boundary="Apple-Mail=_9C8594CA-7189-4A3E-B3DD-B837D0CB773E" 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 Date: Wed, 12 Mar 2025 10:17:45 +0100 In-Reply-To: Cc: PHP Internals To: Daniel Scherzer References: X-Mailer: Apple Mail (2.3826.400.131.1.6) X-Proofpoint-ORIG-GUID: 5b2pWconnXXZEtT2M3_3L9ezU806kDUa X-Proofpoint-GUID: 5b2pWconnXXZEtT2M3_3L9ezU806kDUa X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1093,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-03-12_03,2025-03-11_02,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 phishscore=0 malwarescore=0 spamscore=0 bulkscore=0 clxscore=1030 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2503120063 From: alwin@garsi.de (Yogarine) --Apple-Mail=_9C8594CA-7189-4A3E-B3DD-B837D0CB773E Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 On 10 Mar 2025, at 20:07, Daniel Scherzer = wrote: > 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 Hi Daniel, To begin, I'm all for a `never` bottom type, and I use it regularly when = I need to write TypeScript. However, I think the example offered in this RFC =E2=80=93 while a valid = one, for now =E2=80=93 isn't the most appropriate use case for a `never` = type. A bottom type is more often used when defining conditional types, = or to assert that the default for a switch/match expression should never = be reached without raising an error that the switch/match cases are not = exhaustive. As such, a `never` type provides a lot of value for static analysis = tools and IDEs, and as a matter of fact both PHPStan[1] and PhpStorm[2] = provide ways to declare a bottom type. Furthermore, when conditional = return types and/or generics are finally implemented in PHP, never will = become even more valuable if not essential. But, when generics eventually do make their way to PHP, it also means = the provided example no longer applies, because you would just be able = to use generic types: ```php interface BackedEnum extends UnitEnum { public T $value; =20 public static function from(T $value): static; public static function tryFrom(T $value): ?static; } ``` So I think it may help sell your RFC if you provide some additional = context illustrating the use of the `never` type in generics and static = analysis. Otherwise I fear that some people may interpret `never` as a = stopgap solution until we get generics. Alwin [1] https://phpstan.org/writing-php-code/phpdoc-types#bottom-type [2] = https://github.com/JetBrains/phpstorm-attributes/blob/master/README.md#nor= eturn --Apple-Mail=_9C8594CA-7189-4A3E-B3DD-B837D0CB773E Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8
On 10 Mar 2025, at = 20:07, Daniel Scherzer <daniel.e.scherzer@gmail.com> = wrote:
Hi= internals,

I'd like to start discussion on a new RFC = about allowing `never` for parameter types when declaring a = method.


-Daniel

Hi Daniel,

To = begin, I'm all for a `never` bottom type, and I use it regularly when I = need to write TypeScript.

However, I think the = example offered in this RFC =E2=80=93 while a valid one, for now =E2=80=93= isn't the most appropriate use case for a `never` type. A bottom type = is more often used when defining conditional types, or to assert that = the default for a switch/match expression should never be reached = without raising an error that the switch/match cases are not = exhaustive.

As such, a `never` type provides a = lot of value for static analysis tools and IDEs, and as a matter of fact = both PHPStan[1] and PhpStorm[2] provide ways to declare a bottom type. = Furthermore, when conditional return types and/or generics are finally = implemented in PHP, never will become even more valuable if not = essential.

But, when generics eventually do = make their way to PHP, it also means the provided example no longer = applies, because you would just be able to use generic = types:

```php
interface = BackedEnum<T> extends UnitEnum {
  public T = $value;
 
  public static function from(T = $value): static;
  public static function tryFrom(T = $value): = ?static;
}
```

So I = think it may help sell your RFC if you provide some additional context = illustrating the use of the `never` type in generics and static = analysis. Otherwise I fear that some people may interpret `never` as a = stopgap solution until we get = generics.

Alwin

= --Apple-Mail=_9C8594CA-7189-4A3E-B3DD-B837D0CB773E--