>
> You might want to have a stiff drink before reading through the examples
> in this RFC then: https://wiki.php.net/rfc/string_to_number_comparison


I've already browsed this RFC, I think it's a step in the right direction
and agree with it for the most part, with 2 exceptions:

- the one we're taking about here: disallow both leading AND trailing
whitespace in numeric strings
- I would also strongly suggest that 2 strings are always compared
byte-by-byte; IMO it does (*somehow*) make sense that 42 == "42.0", but it
DOES NOT make sense that "42" == "42.0". I mean, when you're comparing a
string to a number, surely you expect some kind of conversion to occur in
one way or another, but when comparing two strings, why this magic? Is that
because we want to enforce IF ($a == $b) AND ($b == $c) THEN ($a == $c) ?
If so, I would push this RFC one step further towards strictness and
suggest that:

```php
var_dump(42 == "42"); // true
var_dump(42 == "42.0"); // false
```

Which would meet this enforcement. I come across code that benefits from
automatic conversion between an integer and its string representation every
day, but have yet to encounter any code that would benefit from quirks such
as 42 == "42.0". Getting an integer as an int or as a string is no big
deal, but as soon as you start dealing with decimal strings (and floats),
you're asking for trouble if you're relying on such quirks if you ask me.

Also, may I suggest that these 2 RFCs be merged together?

https://wiki.php.net/rfc/string_to_number_comparison
https://wiki.php.net/rfc/trailing_whitespace_numerics

Ben

On Tue, 26 Mar 2019 at 23:28, Rowan Collins <rowan.coll...@gmail.com> wrote:

> On 26/03/2019 21:54, Benjamin Morel wrote:
> > I almost had a heart attack after running this code. I knew that PHP had
> a
> > few quirks when comparing different types, but I had long taken for
> granted
> > that comparing 2 *strings *performed a byte-by-byte comparison.
>
>
> You might want to have a stiff drink before reading through the examples
> in this RFC then: https://wiki.php.net/rfc/string_to_number_comparison
>
> Regards,
>
> --
> Rowan Collins
> [IMSoP]
>
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Reply via email to