Bug #75568 [NEW]: a strange behavior of float and string comparison

From: Date: Fri, 24 Nov 2017 16:10:14 +0000
Subject: Bug #75568 [NEW]: a strange behavior of float and string comparison
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-212713@lists.php.net to get a copy of this message
From: 605231181 at qq dot com Operating system: not related PHP version: 7.1.12 Package: *General Issues Bug Type: Bug Bug description:a strange behavior of float and string comparison Description: ------------ I've recently noticed a strange behavior of php comparison on float/double and string, i searched online but found nothing related, I'm not sure if it's a real bug or not, so I've posted it here. I understand there might be some type conversion problem, but i don't quite understand what's really going on. I understand the problem is about float number, but I'm not using === to compare, and the output(var_dump) of two value is same, so I expect same results here. As a note, not every case result wrong, some case is working. Test script: --------------- code is running in Psy Shell v0.8.2, but the issue can be reproduced anywhere. >>> $a=986365.1;$b='986365.1';var_dump($a,$b,$a==$b); float(986365.1) string(8) "986365.1" bool(true) >>> $a='73.01'*13510;$b='986365.1';var_dump($a,$b,$a==$b); float(986365.1) string(8) "986365.1" bool(false) >>> $a='5.01'*10.1;$b='50.601';var_dump($a,$b,$a==$b); float(50.601) string(6) "50.601" bool(true) Expected result: ---------------- i expect same result bool(true) in all test scripts. -- Edit bug report at https://bugs.php.net/bug.php?id=75568&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75568&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75568&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75568&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=75568&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=75568&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=75568&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=75568&r=needscript Try newer version: https://bugs.php.net/fix.php?id=75568&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=75568&r=support Expected behavior: https://bugs.php.net/fix.php?id=75568&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=75568&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=75568&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=75568&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75568&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=75568&r=dst IIS Stability: https://bugs.php.net/fix.php?id=75568&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=75568&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=75568&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=75568&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=75568&r=mysqlcfg

« previous php.bugs (#212713) next »