ср, 27 февр. 2019 г. в 10:06, Kingsquare.nl - Robin Speekenbrink <
ro...@kingsquare.nl>:

> Op di 26 feb. 2019 om 13:27 schreef Nikita Popov <nikita....@gmail.com>:
>
> > Hi internals,
> >
> > I think it is well known that == in PHP is a pretty big footgun. It
> doesn't
> > have to be. I think that type juggling comparisons in a language like PHP
> > have some merit, it's just that the particular semantics of == in PHP
> make
> > it so dangerous. The biggest WTF factor is probably that 0 == "foobar"
> > returns true.
> >
> > I'd like to bring forward an RFC for PHP 8 to change the semantics of ==
> > and other non-strict comparisons, when used between a number and a
> string:
> >
> > https://wiki.php.net/rfc/string_to_number_comparison
> >
> > ...
> >
> > Regards,
> > Nikita
> >
>
> Dear All,
>
> From a user-space POV this is a very good way forward and I (personally)
> really like the proposal of having a transitional period (7.4 anyone?)
>
> As of the 0 == "" bit: I do think that an empty string is widespread
> regarded as falsey-string... Thus 0 == "" sould IMHO return true...
>
> Just my 2 cents, keep up the excellent Nikita!
> (and everyone else ofcourse)
>
> Regards,
> Robin
>

It's a bad idea to leave 0 == "" - remember - we are dealing with strings
that come in via HTTP, so when you handle form input a 0 can be a valid
input value, but an empty string is not.
Sure, a === is better used here or empty(), but we should not leave
edge cases like these. This is a string to a number comparison - it should
trigger notice or error or whatever is designed to happen when "abc" == 123
is being done.
-- 
Arvīds Godjuks

+371 26 851 664
arvids.godj...@gmail.com
Skype: psihius
Telegram: @psihius https://t.me/psihius

Reply via email to