Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117619 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 72228 invoked from network); 26 Apr 2022 13:26:08 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 Apr 2022 13:26:08 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A4060180542 for ; Tue, 26 Apr 2022 08:01:23 -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 08:01:22 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by darkcity.gna.ch (Postfix) with ESMTP id CC3841507CF9 for ; Tue, 26 Apr 2022 17:01:20 +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 eUs36HTsZEdR for ; Tue, 26 Apr 2022 17:01:19 +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 BF14E15166B0 for ; Tue, 26 Apr 2022 17:01:19 +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 17:01:19 +0200 References: <3fcdfa2c-7a9c-d634-ea56-8b1e5bf1a911@gmx.net> <08ddcfdf-54a8-6f6d-979b-7d819a882f4e@gmx.net> To: PHP Developers Mailing List In-Reply-To: <08ddcfdf-54a8-6f6d-979b-7d819a882f4e@gmx.net> Message-ID: <1DD783DC-236A-40F2-987A-5F483A68E0D4@cschneid.com> 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 15:16 schrieb Andreas Leathley : > On 26.04.22 14:47, Christian Schneider wrote: >> 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 >=20 > That would not be my target - in an if expression a lot more values = are > allowed anyway (arrays, objects, etc.), so this is not about = determining > truthiness, but actual conversions to a bool type, like a bool > parameter, a bool return type or a bool property type. I see, so as long as there are no bool type hints for function = parameters everything would be the same. This would lead to a minor asymmetry for $preserve =3D "yes"; if ($preserve) # Silently working, true array_slice($array, $offset, preserve_keys: $preserve)); = # Not working any more I assume your solution would be to add an explicit cast to bool? i.e. = something along the lines of array_slice($array, $offset, preserve_keys: = (bool)$preserve)); # Explicit cast to silence implicit conversion I'm a bit worried about having to keep two different convert-to-bool = rule sets in mind (implicit vs. explicit) and about the additional = casts. Regards, - Chris