Bug #81452 [NEW]: if comparison with '==' operator between integer and a string
| From: | remy dot dernat at umontpellier dot fr | Date: | Fri, 17 Sep 2021 08:59:29 +0000 |
| Subject: | Bug #81452 [NEW]: if comparison with '==' operator between integer and a string | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-236661@lists.php.net to get a copy of this message | ||
From: remy dot dernat at umontpellier dot fr
Operating system: linux kernel 5.13.14-100.fc33
PHP version: 7.4.23
Package: Unknown/Other Function
Bug Type: Bug
Bug description:if comparison with '==' operator between integer and a string
Description:
------------
I have a generic function which is comparing two string.
The success string in my code is "1" (an integer actually). Sometimes,
the comparing string is something like a date DD/MM/YY or MM/DD/YY. If
the first two characters are 1 or 01 it will result in a succeeded
condition.
I do not want to test if the compared string is a date or not, because,
as I previously said, I may have many values, and I still want a Ok
result if I compare int "1" to "01" or "1" string (so, I do not want
to
use "===").
Is there something special with "/" character, which creates such an
issue ? Indeed, if I try to do a cast from this special string to a
float it results in the "1" value anyway.
Test script:
---------------
$str1 = "01/2/21";
//$str1 = "01";
$str2 = 1;
if($str1 == $str2) {
echo "Ok !!!\n";
} else { echo "Not equal\n"; }
//echo var_dump($str1);
//echo "\n";
//echo var_dump($str2);
//echo "\n";
Expected result:
----------------
Not equal
Actual result:
--------------
Ok !!!
--
Edit bug report at https://bugs.php.net/bug.php?id=81452&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=81452&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=81452&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=81452&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=81452&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=81452&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=81452&r=support
Expected behavior: https://bugs.php.net/fix.php?id=81452&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=81452&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=81452&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=81452&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=81452&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=81452&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=81452&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=81452&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=81452&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=81452&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=81452&r=mysqlcfg