Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117608 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 42695 invoked from network); 26 Apr 2022 08:19:20 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 Apr 2022 08:19:20 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 52807180384 for ; Tue, 26 Apr 2022 02:54:32 -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,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,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.17.21]) (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 ; Tue, 26 Apr 2022 02:54:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1650966870; bh=2W2fEf1+SdkIj+H15xsk+4W9N8hRtkrFQ10AgIcKFLs=; h=X-UI-Sender-Class:Date:To:From:Subject; b=f4jvSsE4NxqQkB5pNROvk72qfOlMXYoHz69u4dk+0xCtfbHXQbHOEl1yWNcT4vXkQ G0cNCOKJONPmauUW/j8M4Wx8aqtQnE3CBJ8IF9bg06swTGkzdXY/iO932LUz2AVhK8 b12omQo3Ox59xRt/QgxhDkEJyrlmet8qfij2NsP0= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.178.120] ([24.134.51.41]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MpDNf-1oEI0I3ERL-00qgMg for ; Tue, 26 Apr 2022 11:54:29 +0200 Content-Type: multipart/alternative; boundary="------------cmdbNOdx3D7si2O2CLR2Rrt5" Message-ID: <3fcdfa2c-7a9c-d634-ea56-8b1e5bf1a911@gmx.net> Date: Tue, 26 Apr 2022 11:54:29 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Content-Language: en-US To: PHP Developers Mailing List X-Provags-ID: V03:K1:zYvlW4wY3YFBB3L4x0RfCXzigMM0De964fZABHR2vvItdYfLXgJ ScHIlf9mQgPU0D2eDpsoPOqWjmmvbqqWhkPcosjpgNd/rUyUyFuZVgabba7TPJFNsKGI5zc LHNmfyJ1iqpMXRWdiXGrjCXKzTggVxcVdeVXIwh174f7uCL6bAKztnbfsfDjTWWHgjDcnj5 r8MlRZrduWIH31fTUfQBQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:fQxmhCbGzdw=:YWIb9BGAJiO4/QcvavBiYL aAbTfnq9W4Fb9I7yizlYcs4qtpS2g8NdUniZ8XbjcG9kuLjcGoeEeCYfQ24zhoRjVtz7Oy6QY 47FRY6Lw16komWTCIS+MpB+2ZFrqTyOBcovGiF6CdJRGM5l63Y3YMJ2ORJ4wHhpoK70xZABR7 EBquept8o6PDKr0oO3cem7xEW7JzqtWoCoZd7tqKplLRY8RAxS7ECuIRVM0VouJI6+OR3rmke wQ/IrHGfiakWj8oG6YikV7AZLOjglX5xZzdnzcSoIcdWwf7fWXj7TkkL8PoMcQ2W6mpBP6Soq 8mJeHnBnb9dpVFW4OXliAXvt2G36Kum9iUN2EjUyhXGdFnYEVprp+du3KF5jc/zO6/WcsOJ19 c5IzMxS+cUFu6YEQn3nJqCtFAl6yeeBvcAVwjN5jjg2IFKKBdM98f0YkxJ275jMDAF8Jj3GOF ZCbVJR39yFjIHxM/QnmKKXRhhRBygWWArwF73MW056TN/qPx5GCofS8/9q2EMys0csmcX22QH 5V3GLNUPiFBPJLGjvrRWdpAAsWct5aLaMnge+Yyn8cgyJrzNs7QHuuhu6xc8URlY2euF78qtb idZ4FUbMSBXiI6PlDqk3fq5x3yy2Y6jMFc0myLZbBKeg+sHBG6ASvS2JsFka7IbSbuE23A9z+ 0kHgkaP18GdqEeiOkRyj91CxvwLnOlaYBJ/Lx0UJsjHrCnN+YtF4Rqw1AGsjVuX8N0urpQHpm 7W5toqa4hBUrYo4WW3hNaBSdBpf/7tbvK9vnA3PytWPNma4TMI1IKYGizACqqwycNar75gqMY ZyKmdDVpujXBgXIXL+BHjH+PvPy3jpMdLFwrPU8Qp8Fni+0r8mgSkKhr3T0aQEppsQX9DSPYm q8QJ4gO/sEl6rtReRr6mYTvMc51/OoOxuvNH9KocdHsFA/9nlbIihESguSCD7Px5ayk7LlDas L5+MyA3nxD9lHVVrCmYUe0fT9cxH3XXvgt5Ie+KNYyupVKhGauje+mFOGykaiCgpM8rg3nOpP 1SgKf00RsvtMokWROfco8+dS0Z/uB/SCmVdJ066nt4d1ek7mZHI6q8ebFNoVUMZVrutrCwj5k uuigwUdr726Mfw= Subject: Stricter implicit boolean coercions From: a.leathley@gmx.net (Andreas Leathley) --------------cmdbNOdx3D7si2O2CLR2Rrt5 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable Hello Internals, Implicit type coercions (when not using strict_types) have become increasingly less lossy/surprising in PHP, especially coercions to integer and float, where you get a TypeError if you pass a non-numeric string to an integer parameter, and a deprecation notice if you pass a float(-string) with a fractional part to an integer parameter. The big exception so far is coercions to boolean, where you can provide any scalar value and never get an error or a notice. Any non-empty string (except "0") is converted to true and any non-zero integer or float is converted to true. From my perspective this can easily lead to hidden bugs, for example when passing the wrong variable to a boolean argument or boolean property. Passing a string like "hello" as a boolean is probably a bug, just like passing the number 854 or the float 0.1 . "on" and "off" and "true" and "false" all lead to a boolean true, as examples of strings that could be used in applications and might not all be meant as a value of true. I have not found any past proposals or discussions to change boolean coercions, so I would like to find out how the thoughts on internals are to change this, or if there are any reasons not to change this that I have not thought of. Only allowing the following values would make sense from my perspective: '1' =3D> true 1 =3D> true 1.0 =3D> true '' =3D> false '0' =3D> false 0 =3D> false 0.0 =3D> false I can also see a case for allowing the strings 'true' and 'false', and changing 'false' to be coerced to false, but that would be a BC break. I am not sure if that is worthwhile. Anything else would emit either a notice or a warning as a first step (to be determined). My main goal would be to make these probably-not-boolean usages more visible in codebases. Depending on the feedback here I would create an RFC and try to do an implementation (to then discuss it in more detail), so as of now this is mostly about getting some basic feedback on such a change, and if someone else has had any similar thoughts/plans. Thanks for any feedback! Andreas Leathley --------------cmdbNOdx3D7si2O2CLR2Rrt5--