Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117776 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 17576 invoked from network); 23 May 2022 17:57:49 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 23 May 2022 17:57:49 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3D68F18050B for ; Mon, 23 May 2022 12:39:53 -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.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS8560 212.227.0.0/16 X-Spam-Virus: No X-Envelope-From: Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 23 May 2022 12:39:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1653334791; bh=Mc29MjQ53+1mpo0EjyYq/ZE4c/qmORBHYi9YdDPCHA8=; h=X-UI-Sender-Class:Date:Subject:To:References:From:In-Reply-To; b=KgATtrWb7HKuQzODpkeQs9knkZABcvPuaGicjvSu8JsZMyAq9sspc4+3If2EHa/9n 2eMK/0s+PN2g9bsddTni4v4Bg68J1WMzYma1MPu/km4Xf+3wVKbNcq0CTD7U+/uMx2 qbvPWnuu50LxKW1zvxi6kUcD8nFCJcctnkk2suEM= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.178.120] ([24.134.51.41]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1M2f5Z-1nrJA80JmZ-004EcA for ; Mon, 23 May 2022 21:39:51 +0200 Message-ID: <189acb71-bd57-85d2-6159-ab80bad30e88@gmx.net> Date: Mon, 23 May 2022 21:39:50 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Content-Language: en-US To: internals@lists.php.net References: <628BD938.1010409@adviesenzo.nl> In-Reply-To: <628BD938.1010409@adviesenzo.nl> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:aiZrhsi6WoqSKAJRd9WukQjbRZLjnqVODuHKZVw5Kpr/4Z2W42O QcYAoRrfCzuc3MYjM+ihyipmI3fJlx7CUSTY5muDg0SZHZmbQg3t+W7wVIDzdMakX2swOJ6 tnUFs9lZR8qZfv3qdStIKug6HPcDWOBfK2sPMRVaq0rqd1dEpu9amm7Bu0BSkBs61380svT FwS/Ic++Hb77G6bpE35yQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:V7bv15+EBrs=:0zhDuWzgY19yK0/6CYSql+ hFUTt1anbqawS/mM3raG9bRCmLd4I9rZ5v6CWuRD9n5eQ8wIExDF/YqPyRMme+8oIFraWIcEv iZp+YwXupAw3V+avb96y3fHV//l8VqTUnl5iXafLDNBCoFJAzfZ4BVsxRgU/jLcAbrHfXY1mV MgKyVbNcAKr7B435vku45JRaZlnIwH8eHmfPZpHnGEl8GZSYDgos1Lp6pIfLAQnWmBv3jhmcW +7EvC3zoAcHgmTiwGh1VuPVHtcFOmuipwM8EPL8y+xBiGp5ISj1RG6L8TNCK361BWBQzvqiMB eFMekLe9gtbETefyTky81U44WktLIkAQiYCwx1+ti22o5lwDykduMxnInM63smYzmM90bRhHx uENxgwbXV8/UCOWSpZ3ceeOXxfMtTLdmqr2c+l9jllSSAzXKO1maWOLazFcx4fbxmVttjv/1R QCVFP9+tHriAVhyH7gMz7koJbOGZUxQh/OmtC9wPtYthFjFCz+W8fWrtq9WMj2OdVaHB4WvIK qmj6yhbvk5LRr1FbUsO6jIvsLADyAmmvg79wtaFLwf3HW3O8f82EaxECUGFMyLa6dIgIsq4U9 2ZTKuyTaddeWThd2PmlEgiLIr82MghppackFgX+dbBtTFdhtN2j9aDEaPCDZY0UVAfLJQb6l8 3VL8sCLzk4EftUupPx2CLfVeds5DqKRL6VnXzUMjRrP4UCC7hZtxw2NIfkOj1TQqMOlaw/XBO c02US5DCTn4LfmVlnag3gieEIYX7v8hPiB225RnR2BBTUffvxo0XBY6F5Gn1eBTi+tkCAnlct tr+g1++2RhuU2nF6+4NRp0jOyeRaLYJB8r5KS1U6o4mmXPgH3oEWSbQIR8GxyEKkCpPtwZwB2 X5MrM1+WZFEjVXkU314/xjB7NEfSML3ExDlotaKnOx7tq6+3/AikNAIz+U+JvUll121bu8Nou yjm8ZuiN/8iENxCCpItA1RC6uJ+64OKTpPpCt4FeDyZVsJDn2ayAI5lSg4EEIJG7/GX5n05v0 UPuOOLnUkxVNGx6hWIifYbzxuGAYgH4Itp7WuAtzGuMe1o8W29cEOmFAmeDdVfBXPNdBnzAan zxPaMdiy+hMYuv2vR8FNFyWhIrPksfSPL7MYT5uNfia7GqNQqYEmNzsRA== Subject: Re: [PHP-DEV] [Discussion] Stricter implicit boolean coercions From: a.leathley@gmx.net (Andreas Leathley) On 23.05.22 20:58, Juliette Reinders Folmer wrote: > This RFC worries me as, in my opinion, it makes PHP's behaviour more > surprising and inconsistent, not less. > > It also raises the cognitive complexity for developers by yet another > level. > > 1. It introduces a new interpretation of boolean type coercion, which > is only applied against type declarations. > 2. This new interpretation is not consistent with "normal" boolean > type coercion, not consistent with strict types (no coercion) and also > not consistent with what is considered a valid boolean value by the > Filter extension. I am not sure what you mean by "normal" boolean type coercion and how it would be inconsistent with those. The RFC does not change the behavior of boolean type coercions, it just points out possibly surprising coercion= s. The filter extension has its very own interpretation of how to validate a boolean which is completely incompatible with how PHP does implicit type coercions already. Yet people using the filter extension are not affected by this RFC at all, they have already chosen their way to convert a value to boolean. But comparing the filter extension with the implicit type conversion does show how dangerous it can be to for example switch from FILTER_VALIDATE_BOOLEAN (with FILTER_NULL_ON_FAILURE) to the implicit boolean conversions from PHP: with the filter extension "false", "off" and "no" are converted to false, while all these values are silently converted to true by implicit boolean conversion by PHP. People switching from the filter extension to the built-in types of PHP have another way of shooting themselves in the foot, and it is easy to miss the change in behavior. > While I agree that the current behaviour of PHP can hide bugs, I fear > that even more bugs will be introduced when PHP contains yet a third > form of coercion to boolean and the type coercion used is dependent on > the context. Assuming from the rest of your response, I am assuming you mean "truthiness" comparisons, like in if statements and other expressions. Those are already different from coercions to typed booleans and have different semantics. In an if statement you can check for truthiness with any type, while a typed boolean only accepts scalar values. I am seeing an advantage of further separating those use cases, as a misconception seems to exist that a check for truthiness is just a conversion to boolean. Having clearer semantics would actually lower cognitive complexity from my perspective - knowing that only 7 values are considered sensible for a typed boolean and getting a notice for any other values makes it a lot clearer how it behaves and when I as a developer will get warned. > I fear this will only lead to more bugs, not less (because people new > to PHP will learn the "type declaration" based boolean coercion rules > and assume they apply everywhere). But they would actually apply anywhere, as far as I know: My suggested allowed values for typed booleans can be used in if statements and lead to the exact same behavior. > I also fear that for code bases which do not (yet) use scalar type > declarations, this will be one more argument not to introduce scalar > type declarations (while they should). My suggestion is far less impactful for "legacy" codebases compared to the other scalar type checking - an "int" parameter only accepting valid numbers and leading to a TypeError otherwise is a much bigger hurdle from my perspective than introducing a deprecation notice for a suspect boolean type coercion. I cannot really believe that "failed" not being auto-coerced to true will be the straw that breaks the camels back in legacy codebases. And again: It is just a deprecation notice, I even amended the RFC to say that this being elevated to a TypeError will have to be decided after the impact of the deprecation notices become clear, not now. My goal is not necessarily to be as strict as possible but rather point out to developers where something might be going wrong. > I'd say that for this RFC to be acceptable it would need to apply to > all implicit type coercions to boolean. However, the BC-break that > would cause and the fall-out of this for non-greenfields codebases is > just too huge, which, to me, makes this RFC a very strong no-no. I will amend the RFC to show how typed booleans already have their own type coercions that are not the same as the truthiness checks in if or similar expressions - thanks for pointing that out and showing that there is some confusion there that might benefit from a clearer explanation. Changing how truthiness is evaluated in PHP makes no sense to me though, and I don't think such a drastic step is necessary to get a lot of benefits. If you have further feedback, I would be happy to hear it. So far I have not gotten much feedback, and most of it was going towards being positive, so being able to get to know the other perspective would help to address it in the RFC and improve it overall.