Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117617 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 66451 invoked from network); 26 Apr 2022 12:17:53 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 Apr 2022 12:17:53 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2E9CD1804A8 for ; Tue, 26 Apr 2022 06:53:09 -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,NICE_REPLY_A, 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.20]) (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 06:53:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1650981187; bh=oUd295nARfqgG2hEDi7WpvW6m5snX9xaBU412Lgc4lk=; h=X-UI-Sender-Class:Date:Subject:To:References:From:In-Reply-To; b=NF74vkeZAwl3bDbxJb55uH4yTE7DrObmMIib61enUQgm8RkD+gHRjGQ6thxR78jwC 7+pQGE2+FLNc/QTwIphFN1BOX31FFzdrdaAMddcIhVa2rPffA9vZhMPne00BiRY6uv PtBN+vtkidhMMChsr22A6vCwFcoe3S06+UrhLKV0= 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 1N5VD8-1nxvui3t50-016u92 for ; Tue, 26 Apr 2022 15:53:06 +0200 Message-ID: <5ceeb3f0-0f01-8b93-00ca-9947c9c69e4c@gmx.net> Date: Tue, 26 Apr 2022 15:53:06 +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: internals@lists.php.net References: <3fcdfa2c-7a9c-d634-ea56-8b1e5bf1a911@gmx.net> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:tIFGUKInksoesZkoWh/pOVZMK4whnz3BQGb7zLzyN7cKJpTVTWk fpoHolMcESHfycGTsu/JdAkqar5R4gaou1HSaH12etEncuHYaAuZwfTSnkaGmYnA/FY3GwX 8/Y1QW+03TnurkDHCJxGd5FW7LO22cz9oU7S8s51iLodqlWLYiTedTWk+EbcJpqCv4RJiKw mW0++fcTRdtUPqBOdJ/9Q== X-UI-Out-Filterresults: notjunk:1;V03:K0:+IPPLoe07WY=:ac0myJC9IqAeUkr5JsZjYU txPJXKIDx2yRFg3ijzPBOLrujtOFafXRjgR+r2OrCNVNfcD/xorvcSE7xXQuh1Wmorc5cKWaY bQQUP4sZDHflL+F1CIRC7139mSHHX9Ap9r/+1NI+2471ucCLePi9jCMcQ1AK09bqu8Yv2dzhH 4MGiSKQ8KC0ERQUXFaTgAVy9Wmys7OuhU4r0gaGkmcNZn/vnBhwPNkIOTmM5Mno52Vw1gOmAu xCGxb1GHA2i02IN79gp75PO+GjlqbJXaYNTT6YGCJzjoQhhNYNCqfiB/pWC1MOdsoj79vr6CX pyenk0janvEWi8btcYuQKQjpEZ7CrvJQhkfF2CJI9VSQ8FS/g+3HHHf/7P9ji9+YYJ7QKy+FN dqueOeJioBnNfJJC7CYdy65oAe5JYPn6ltd1WbzVtkqtSE1IDk0ESyzGawJQf2p1pLRVG2Fk7 hdz+0GxRu++zOFiMIfx6b52tiosllr46nkhX2vye8LNnTs7629qLszon+hJKGsXHlMllkRSOq xrU6n13owsQ9/5BLbdkwa45t7FwBilPxUcdHiWgE5itMty7kgEWWrhslQXpBbnv4ZNZfViVdc UmoEKZtoCNOpb+MmwKCBRfKZLXZ1ckERD4I2xCjcY7QqgUBscobIImwbHH1raM4s7GZej3vNH XCQ28XD1m9im8N9qi5r364pPt8zpdCBPpGOoFktkB1p53VQXeMTfz6Odh1mrHi8X2hFf+9BuS N6RHq/7Hx04aRxRrOivyT5B3vYmfRTXmXi/gNarj5znCS9VWJ/02xYztcPFvauaLstD9A5Mn3 EEUM15p8zDA2yghMk6TH7S2cASRfEb3P5CvHRtCL8dbQjpI6a1Uh/jXtxVVhJtMOAStnuAlia v9AOp/sBUujy4oh0nNvBrtgmRQ3fGTnNcY9GOCat6w6z/haGWkqSXlFWF/ah+UQgbg8GF7yzH zuzwo4OLmRqYazK3WTHGCvJwI0YDXqJUknSywn3t0/R5xYaY1aAK0JRFL0BQnRy9vIZCJV6TQ aXn3DlDswpDg74jlL6SufSB+qSlWDqJTPmZLCGhudhgDcX5HQvh+J3DQ93blhp7FEd8Dp6FLj tg8zWRaGTbGUzQ= Subject: Re: [PHP-DEV] Stricter implicit boolean coercions From: a.leathley@gmx.net (Andreas Leathley) On 26.04.22 15:27, Rowan Tommins wrote: > > I was actually thinking about this the other day, in the context of > adding new cast functions which reject more values than our current > explicit casts. > This is also something I am interested in - having functions which do the same as implicit type casts, so something like "coerce_to_int('hello')" would lead to a TypeError like it would when passing it to an int parameter, and maybe "is_coerceable_to_int('hello')" which would return false, so it would be possible to check values the same way as PHP does internally. The current explicit cast functions are quite heavy-handed and not great for every situation - when parsing a CSV or getting data from a database I would rather coerce values where an error could occur if it doesn't make sense than to explicitely cast and not even notice if the value made no sense at all. > When I started thinking about booleans, it was much harder to define > what makes sense. I've certainly seen new programmers confused that > (bool)'false' is true, and having it error would usually be more > helpful; but (bool)'on' being true is useful when dealing with HTML > forms, for instance. 'on' is only true by "accident" though, because it is a non-empty string, not because of its meaning, and then it is likely that the value 'off' could also be added at some point - which also would be true. One of the big reasons of starting this discussion is because of HTML forms, as that is where people might add values and not know what that leads to in PHP. At these application boundaries it would be helpful to get a clear message what value was converted to true (but might have lost information by doing that) and what other value to use which is considered more clear.