Edit report at https://bugs.php.net/bug.php?id=54547&edit=1
ID: 54547
Comment by: the dot assimilator at gmail dot com
Reported by: peter dot ritt at gmx dot net
Summary: wrong equality of string numbers
Status: Not a bug
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:
This isn't just a bug, it's a summary of PHP as a language: broken by design.
Previous Comments:
------------------------------------------------------------------------
[2012-04-13 10:53:24] sesser@php.net
This behaviour is for sure a bug. The == vs. === argument does not apply here.
PHP should not perform the type conversion for the comparison if the result of the
type conversion does not fit into the actual type converted to.
------------------------------------------------------------------------
[2012-04-13 10:15:52] yohgaki@php.net
Just a comment for users who would like to use large numbers.
There are bcmath and gmp modules for large number arithmetic.
------------------------------------------------------------------------
[2012-04-13 07:08:00] pajoye@php.net
ok, enough arguing. There is no bug here.
------------------------------------------------------------------------
[2012-04-13 03:13:57] four dot zero dot one dot unauthorized at gmail dot com
This behavior is documented here:
http://php.net/manual/en/language.operators.comparison.php
"If you compare a number with a string or the comparison involves numerical strings, then each
string is converted to a number and the comparison performed numerically. These rules also apply to
the switch statement. The type conversion does not take place when the comparison is === or !== as
this involves comparing the type as well as the value. "
Shouldn't this feature of converting numerical strings to numbers during loose comparison
operations between two strings be dropped? If a developer wanted to compare values given during
POST or GET processing AS numbers, they should cast the inputs to (int) or (float) first. There
really should be a fundamental shift away from catering to developer laziness, and force developers
to pay more attention to variable and input handling on their own.
------------------------------------------------------------------------
[2012-04-13 01:10:44] the dot matt dot kantor at gmail dot com
@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.
------------------------------------------------------------------------
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