On Tue, 20 Sep 2016 at 02:20 Dan Ackroyd <dan...@basereality.com> wrote:

> Hi Vesa,
> On 19 September 2016 at 14:04, Vesa Kaihlavirta <vpkai...@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.

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
> 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



> cheers
> Dan

Reply via email to