Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117775 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 16268 invoked from network); 23 May 2022 17:56:26 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 23 May 2022 17:56:26 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 542241804D0 for ; Mon, 23 May 2022 12:38:30 -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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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:38:29 -0700 (PDT) Received: by mail-wm1-f48.google.com with SMTP id p189so9411341wmp.3 for ; Mon, 23 May 2022 12:38:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=craigfrancis.co.uk; s=default; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=Ptv0kVIuFzgaI8UGzScp38+CpiZDOnPmPgvT+q7t3Ms=; b=VVsDZNzi0wRCdtIcO6BYT4Kal2WLBYDPotwnnAj+gkh+7mxzDPYJj554M2jw9VXapO BjmT32T+VOck1IMAiEtFx3ypkQ6au5Q9G4yho/M7IIqMmFCuzw/crXau2F9er3i0ZeXZ htEoJgO1v9gTAqsJJH/LB8QcIo1PwxNK5vaqI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=Ptv0kVIuFzgaI8UGzScp38+CpiZDOnPmPgvT+q7t3Ms=; b=RaIRs6cYfQCuw7d4jgk87bJbLKeBx6XMP4v98Z66/SLC5IM/b/UsDykKShHpE8ViFA GiEeQU5N0qCWx713V5DtJp8HJbEBlXo/Zfl2Fp4YbNISNknT1iTEcCQiuaR+tyKd/C1z YXXy/mSQvoN/HDYz/AxJco3vsAXtn3QGvhNjcD9PTo/E7vhHNxb3ym1Elh0HHIkrYxpW OriS5URZAteMGNfrS+fLSgfCI/gLWw0LLO2HD5dhg7/VTZN4TNPNro9N26/5FLG244mw VSUEuTm3MjBzVngcMgf2yU0d8cEVxxPh71DkskuaUgJLXFb0X5v+6s9E29/VpibgpnjG 1VlQ== X-Gm-Message-State: AOAM532arbb023CulsZtu6FGuQVcyVPeBoDGadW9MvH0/Xt2QUItxEJO aCqs3ZaI4l8t779jnQ1FKHQ1MA== X-Google-Smtp-Source: ABdhPJy6pA6p++2ApeVkKsbF6AwnRIxMDArV8Gbvho4Fkx1SXvHuiBc1CjInKuy0Gyy4aiCoRWcWaQ== X-Received: by 2002:a05:600c:3d16:b0:394:4ff0:d818 with SMTP id bh22-20020a05600c3d1600b003944ff0d818mr523636wmb.5.1653334708631; Mon, 23 May 2022 12:38:28 -0700 (PDT) Received: from smtpclient.apple ([94.173.138.98]) by smtp.gmail.com with ESMTPSA id f22-20020a1cc916000000b003974b95d897sm69080wmb.37.2022.05.23.12.38.27 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 May 2022 12:38:27 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.80.82.1.1\)) In-Reply-To: <628BD938.1010409@adviesenzo.nl> Date: Mon, 23 May 2022 20:38:26 +0100 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: References: <628BD938.1010409@adviesenzo.nl> To: Juliette Reinders Folmer X-Mailer: Apple Mail (2.3696.80.82.1.1) Subject: Re: [PHP-DEV] [Discussion] Stricter implicit boolean coercions From: craig@craigfrancis.co.uk (Craig Francis) On 23 May 2022, at 19:58, Juliette Reinders Folmer = wrote: > 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). >=20 > 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. Forgive my ignorance, but when scalar types were introduced, I initially = assumed type coercion would use the same rules as `strval($var)`, = `(string) $val`, `'a' . $val`, `intval($val)`, etc. I now appreciate = that isn't the case, but I never understood why the following functions = were not equivalent: ``` function my_function1($s, $i, $f, $b) { $s =3D strval($s); $i =3D intval($i); $f =3D floatval($f); $b =3D boolval($b); var_dump($s, $i, $f, $b); } function my_function2(string $s, int $i, float $f, bool $b) { var_dump($s, $i, $f, $b); } ``` Where the second function, using scalar type declarations, has the = advantage of being much shorter, and clearer for Static Analysis, IDE's, = documentation, etc... if only it was as easy to add to existing = projects. This isn't to say `boolval()` and other ways of changing type to a = boolean couldn't throw a type error with unrecognised strings (e.g. = "false"), and doing so might make sense (although I do share Juliette's = concerns about the BC-breaks). Craig