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 <>
My idea is to add a strict_comparisons declaration that you can add at
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
I think it deserves an RFC.
+1 for RFC
Cool! I'll write some more unit test cases and start working on the RFC

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

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


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.


PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:

Reply via email to