Re: RFC: Strict comparisons

From: Date: Wed, 21 Sep 2016 13:26:32 +0000
Subject: Re: RFC: Strict comparisons
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-96054@lists.php.net to get a copy of this message
Am 21.09.16 um 14:49 schrieb Vesa Kaihlavirta:
On Tue, 20 Sep 2016 at 02:20 Dan Ackroyd <danack@basereality.com> wrote:
Hi Vesa, On 19 September 2016 at 14:04, Vesa Kaihlavirta <vpkaihla@gmail.com> 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

« previous php.internals (#96054) next »