Edit report at https://bugs.php.net/bug.php?id=54547&edit=1
ID: 54547 Updated by: yohg...@php.net 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: Just a comment for users who would like to use large numbers. There are bcmath and gmp modules for large number arithmetic. Previous Comments: ------------------------------------------------------------------------ [2012-04-13 07:08:00] paj...@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. ------------------------------------------------------------------------ [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. ------------------------------------------------------------------------ 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