#41905 [Opn->Bgs]: Incorrect String Compare with '=='
| From: | pajoye@php.net | Date: | Thu, 05 Jul 2007 14:28:12 +0000 |
| Subject: | #41905 [Opn->Bgs]: Incorrect String Compare with '==' | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-114676@lists.php.net to get a copy of this message | ||
ID: 41905
Updated by: pajoye@php.net
Reported By: domluc at gmail dot com
-Status: Open
+Status: Bogus
Bug Type: Strings related
Operating System: GNU/Linux Debian
PHP Version: 4.4.7
New Comment:
'==' will see the strings as numeric values, use === if you expect a
type safe comparison (as you noticed and documented).
Previous Comments:
------------------------------------------------------------------------
[2007-07-05 14:20:27] domluc at gmail dot com
Description:
------------
Obs:This bug hape in PHP 4.4.x and 5.2.x
I have a string with 17bytes,
sample:
<code>
$var1 = '99990000000650719';
$var2 = '99990000000650718';
</code>
if I compare these strings with:
<code>
if ( $var1 == $var2) echo "Equal"
else echo 'Not Equal'
</code>
it will print Equal, but this is incorrect.
The solution to correct do this, is using '===': $var1 === $var2
But this behavior is wrong.
I beliave that when php engine compare with '==' it cast variables to
integer, and 17th byte is ignored!
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=41905&edit=1