On Wed, 27 Mar 2019 at 14:30, Benjamin Morel <benjamin.mo...@gmail.com>
wrote:

> > It is a well-known feature that you can work with such data without
> previously converting it explicitly to some number type.
>
> I'm not requesting to change this: if you're doing string("3.5") + int(7),
> you should still get float(10.5). What I'm suggesting we change, is
> comparison of numbers and decimal strings.
>
> Thinking about this a bit more, what about following JavaScript semantics?
> I find them really good in this respect:
>
> - when comparing two strings, always use strcmp():
>
> var_dump("42" == "42.0"); // false
> var_dump("3" < "23"); // false
>
> - when comparing a number with a string, cast the string to a number, then
> compare:
>
> var_dump(3 < "23"); // true
> var_dump("3" < 23); // true
> var_dump(42 == "42"); // true
> var_dump(42.0 == "42"); // true
> var_dump(42.5 == "42.5"); // true
> var_dump(42 == "42.0"); // true
>
> - if the string does not represent a valid number, always return false:
>
> var_dump(42 == "42x"); // false
> var_dump(42 == "x42"); // false
> var_dump(1 >= "abc"); // false
> var_dump(1 < "abc"); // false
>
> Note: JavaScript actually allows leading & trailing whitespace around the
> number:
>
> var_dump(42 == " 42 "); // true
>
> On this last point, I'm not sure whether we should allow both leading &
> trailing whitespace, or disallow both of them.
> Other than that, I love the way they handle implicit conversions here. It's
> so much more understandable, easy to remember, and less prone to errors
> IMO.
>
> Ben
>

Isn't this the purpose of Nikic's Saner PHP String comparison RFC?
And in the discussion of this RFC the discussion of accepting trailings
whitespaces came into play.
As most people agree with changing it however trailling and leading spaces
should have the same behavior.

IMHO I think we should accept traillings spaces to make it more consistant
(and have a smaller BC break)
than banning leading and traillings spaces.
Because boths nikic's and Andrea's RFC go hand in hand.

And probably if both these RFC get accepted a new "stricter numerical
string comparison" RFC could see the light
banning leading and trailling whitespaces.

Just my two cents.

Best regards

George P. Banyard

Reply via email to