Edit report at https://bugs.php.net/bug.php?id=54547&edit=1

 ID:                 54547
 Comment by:         the dot matt dot kantor at gmail dot com
 Reported by:        peter dot ritt at gmx dot net
 Summary:            wrong equality of string numbers
 Status:             Verified
 Type:               Bug
 Package:            Unknown/Other Function
 Operating System:   linux
 PHP Version:        5.3.6
 Assigned To:        dmitry
 Block user comment: N
 Private report:     N

 New Comment:

@hholzgra:  Your only-coerce-on-failure proposal would not solve this issue.

Assuming that by "fail" you mean "the comparison evaluates to false", the 
strings would end up being coerced anyway (since they are indeed different), 
they'd become identical floats, and things would be the same as they are now.

If I misunderstood what you meant by "fail", then we'd lose "1" == "1.0", which 
I don't think is something that can (or should) happen.


Previous Comments:
------------------------------------------------------------------------
[2012-04-12 22:45:28] erowid at inbox dot lv

I want to marry it, lather this thread up, and have my way with it. I want to 
have little threads everywhere that are as funny as this xD

------------------------------------------------------------------------
[2012-04-12 22:14:36] chx1975 at gmail dot com

Now, while I can understand why PHP chooses "1" == 1 (HTML, sure) I am not too 
sure how is that relevant when both sides are strings?? I am not quite sure why 
the strings "1" and "1.0" would need to be ==. Just because "1" == 1 and "1.0" 
== 
1 does not mean "1" == "1.0". It's not transitive! Compare FALSE == 0; 0 == 
'x'; 
'x' == TRUE -- if it would be transitive then FALSE == TRUE, surely you don't 
want that.

------------------------------------------------------------------------
[2012-04-12 21:23:40] vinny_182 at hotmail dot com

Equality is equality and neither string or numeric representations of the value 
are equal. The bug IMO is in the conversion from string to float, the 
conversion 
has failed but a valid value is still returned. That's just plain wrong. If you 
wrote unit tests for string to float conversions and this was the input you 
would 
expect it to return a null value or throw an exception.

------------------------------------------------------------------------
[2012-04-12 21:02:06] c at hotmail dot com

"In the majority of cases when dealing with HTTP requests and database results, 
which is what PHP deals with most, the loose comparison makes life easiest on 
the developer."

By 'the developer' I assume you mean people who can't type (string) or (int) ? 
No other language has this issue because they aren't designed around 
programmers who do not really understand how to program. Please make the 
developer's life easier by making comparisons make sense.

------------------------------------------------------------------------
[2012-04-12 20:38:48] elementation at gmail dot com

It's absolutely unreal that this is even a discussion. PHP, the world doesn't 
take you seriously and with bugs like this you provide further fodder.

Principle of Least Surprise — this should be a string comparison.

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=54547


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=54547&edit=1

Reply via email to