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

 ID:                 54547
 Comment by:         vinny_182 at hotmail 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:

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.


Previous Comments:
------------------------------------------------------------------------
[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.

------------------------------------------------------------------------
[2012-04-12 20:32:57] b at hotmail dot vom

I would like to point out Perl is a weakly typed language, just like PHP, and 
has 
no issue with these cases. It's pretty weak from the developers to hide behind 
the "But PHP is weakly typed!" argument.

------------------------------------------------------------------------
[2012-04-12 17:09:41] riel at surriel dot com

Conversion of numeric-looking strings to numbers does not have to be a problem, 
as long as the code in the back end uses arbitrary-precision math. This is 
slower than comparing a type that fits in a CPU register, but once you have 
already spent the time to do an automatic type conversion, that really does not 
matter.

When it comes to an operator like ==, every digit matters. Having == return 
false when two items are different violates the principle of least surprise.

------------------------------------------------------------------------
[2012-04-12 17:03:32] jacob at fakku dot net

@rasmus

I just wanted to point out the issue mentioned in that article and how I felt 
it 
applied to this situation.

At least to me, it seems to me that it's a big deal when '9223372036854775807' 
== 
'9223372036854775808' returns true, even if it's an edge case. But you're right 
about just using ===, which I will do if I ever run into this situation. After 
doing a bit more research I can understand why it is the way it is and I was 
probably too hasty to jump into this thread.

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


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