Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117626 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 91057 invoked from network); 26 Apr 2022 15:51:41 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 Apr 2022 15:51:41 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 29BB518053B for ; Tue, 26 Apr 2022 10:26:58 -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.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS8412 83.65.0.0/16 X-Spam-Virus: No X-Envelope-From: Received: from mail02.x-net.at (mail02.x-net.at [83.65.141.138]) (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 10:26:57 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by mail02.x-net.at (Postfix) with ESMTP id 317D738052F; Tue, 26 Apr 2022 19:26:55 +0200 (CEST) Received: from mail02.x-net.at ([127.0.0.1]) by localhost (mail02.x-net.at [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id qRHE_9HuNfJd; Tue, 26 Apr 2022 19:26:52 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail02.x-net.at (Postfix) with ESMTP id 86AC1380530; Tue, 26 Apr 2022 19:26:52 +0200 (CEST) X-Virus-Scanned: amavisd-new at x-t.at Received: from mail02.x-net.at ([127.0.0.1]) by localhost (mail02.x-net.at [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 5PQMtk-k-mao; Tue, 26 Apr 2022 19:26:52 +0200 (CEST) Received: from [127.0.0.1] (213-225-3-11.nat.highway.a1.net [213.225.3.11]) by mail02.x-net.at (Postfix) with ESMTPSA id 4F05A38052F; Tue, 26 Apr 2022 19:26:52 +0200 (CEST) Date: Tue, 26 Apr 2022 19:26:53 +0200 To: internals@lists.php.net, Christian Schneider User-Agent: K-9 Mail for Android In-Reply-To: <1DD783DC-236A-40F2-987A-5F483A68E0D4@cschneid.com> References: <3fcdfa2c-7a9c-d634-ea56-8b1e5bf1a911@gmx.net> <08ddcfdf-54a8-6f6d-979b-7d819a882f4e@gmx.net> <1DD783DC-236A-40F2-987A-5F483A68E0D4@cschneid.com> Message-ID: <937A832E-6EBE-4A8B-8BEA-E82DC067C81F@dafert.at> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Stricter implicit boolean coercions From: mel@dafert.at (Mel Dafert) >I see, so as long as there are no bool type hints for function parameters = everything would be the same=2E > >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=2Ee=2E= something along the lines of > array_slice($array, $offset, preserve_keys: (bool)$preserve)); # Explic= it 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=2E explicit) and about the additional casts=2E There are already two different convert-to-bool rule sets for array|object|resource|null, where they will be accepted in `if` but reject= ed when passed to a function taking a bool param: ``` $x =3D (object) ['a'=3D> 1]; if ($x) { echo "if\n"; } function takes_bool(bool $param) {} takes_bool($x); // throws TypeError ``` https://3v4l=2Eorg/fCQFL Adding string|float to that list doesn't seem to be that big of a differen= ce here=2E