Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:96054 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 36322 invoked from network); 21 Sep 2016 13:26:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Sep 2016 13:26:37 -0000 Authentication-Results: pb1.pair.com smtp.mail=thomas.lamy@netwake.de; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=thomas.lamy@netwake.de; sender-id=unknown Received-SPF: error (pb1.pair.com: domain netwake.de from 78.47.58.218 cause and error) X-PHP-List-Original-Sender: thomas.lamy@netwake.de X-Host-Fingerprint: 78.47.58.218 srv.netwake.de Received: from [78.47.58.218] ([78.47.58.218:37496] helo=srv.netwake.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7B/84-04117-C8A82E75 for ; Wed, 21 Sep 2016 09:26:36 -0400 Received: from localhost (localhost [127.0.0.1]) by srv.netwake.de (Postfix) with ESMTP id B5A311522FB for ; Wed, 21 Sep 2016 15:26:33 +0200 (CEST) Received: from srv.netwake.de ([127.0.0.1]) by localhost (srv.netwake.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id an__qVUy_Gsb for ; Wed, 21 Sep 2016 15:26:33 +0200 (CEST) Received: from PHPTLamy.local (unknown [213.61.99.98]) (Authenticated sender: thomas.lamy@netwake.de) by srv.netwake.de (Postfix) with ESMTPSA id 09B6315205C for ; Wed, 21 Sep 2016 15:26:32 +0200 (CEST) To: internals@lists.php.net References: Message-ID: Date: Wed, 21 Sep 2016 15:26:32 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] RFC: Strict comparisons From: thomas.lamy@netwake.de (Thomas Lamy) Am 21.09.16 um 14:49 schrieb Vesa Kaihlavirta: > On Tue, 20 Sep 2016 at 02:20 Dan Ackroyd wrote: > >> Hi Vesa, >> >> On 19 September 2016 at 14:04, Vesa Kaihlavirta >> wrote: >>> My idea is to add a strict_comparisons declaration that you can add at >> the >>> beginning of a file in the same way as strict_types. >>> >>> Please take a look and let me know if this would be worth a more official >>> RFC. >> I think it deserves an RFC. +1 for RFC > Cool! I'll write some more unit test cases and start working on the RFC > text. > >> One thing that might make people hesitant about this, is that it's >> likely that you would want to have the occasional weak comparison in a >> file. >> >> However that should mostly covered by just adding a cast where needed >> presumably? e.g. like: >> >> $foo = '5 apples'; >> >> if ((int)$foo == 5) { >> echo "eh, close enough"; >> } >> > Yeah, that works. I added that as a test case. > > What still worries me personally is ===. What do you think would be the > least incorrect way to handle === (and other identicality operations) when > strict_comparisons is in effect? I thought of the following options: > > 1) === works like ==, that is, makes type checks and throws exceptions if > the types don't match > > 2) === is not affected by strict_comparisons. It would then be *weaker* > than == when s_c is on (since it would just return false instead of > throwing). That would offer a sort of a convenient way out of the strictest > comparison mode, but might be confusing. > > 3) === is disabled/not allowed when s_c is on. Would lessen the risk of > confusion. > > > Thoughts? > > --vk I'd prefer (2). At least in our code base (~3M LOC) it's the uptrending comparison, and widely used for type and range checking, imidiately followed by proper handling of the error cases. IMHO anything other than (2) would be too big of a BC break to get votes. Best, Thomas