Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117614 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 60081 invoked from network); 26 Apr 2022 11:12:42 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 Apr 2022 11:12:42 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 265DB180541 for ; Tue, 26 Apr 2022 05:47:57 -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=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS1836 195.49.0.0/17 X-Spam-Virus: No X-Envelope-From: Received: from darkcity.gna.ch (darkcity.gna.ch [195.49.47.11]) (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 05:47:56 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by darkcity.gna.ch (Postfix) with ESMTP id CB2A21507CF9 for ; Tue, 26 Apr 2022 14:47:51 +0200 (CEST) X-Virus-Scanned: amavisd-new at example.com Received: from darkcity.gna.ch ([127.0.0.1]) by localhost (darkcity.gna.ch [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rWK-k9tV-sTg for ; Tue, 26 Apr 2022 14:47:50 +0200 (CEST) Received: from smtpclient.apple (unknown [IPv6:2a02:1210:2ea4:cf00:292a:10e5:5287:7656]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by darkcity.gna.ch (Postfix) with ESMTPSA id A3F5515166B0 for ; Tue, 26 Apr 2022 14:47:49 +0200 (CEST) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.80.82.1.1\)) Date: Tue, 26 Apr 2022 14:47:49 +0200 References: <3fcdfa2c-7a9c-d634-ea56-8b1e5bf1a911@gmx.net> To: PHP Developers Mailing List In-Reply-To: <3fcdfa2c-7a9c-d634-ea56-8b1e5bf1a911@gmx.net> Message-ID: X-Mailer: Apple Mail (2.3696.80.82.1.1) Subject: Re: [PHP-DEV] Stricter implicit boolean coercions From: cschneid@cschneid.com (Christian Schneider) Am 26.04.2022 um 11:54 schrieb Andreas Leathley : > 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. There are two big reasons: - BC: Checking for the truthiness of a value is very common and would = require a lot of code changes. - Some of us like the conciseness of "if ($foo) ...", see below > 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. I'm definitely against adding more special cases like 'false'. Side-note: Removing something like '0' =3D> false is also a BC break, = not just adding 'false'. > 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. One of the big issues I have with this (as well as undefined variables = not being allowed in if ($foo)) is that the replacement constructs are = clunky: if ($foo) =3D>. if (!empty($foo)) For me this is quite a regression in readability but then again that's a = matter of taste. And would !empty($foo) even work in your world or how would empty() be = defined? Regards, - Chris