#41905 [Bgs]: Incorrect String Compare with '=='
| From: | domluc at gmail dot com | Date: | Thu, 05 Jul 2007 14:49:46 +0000 |
| Subject: | #41905 [Bgs]: Incorrect String Compare with '==' | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-114677@lists.php.net to get a copy of this message | ||
ID: 41905
User updated by: domluc at gmail dot com
Reported By: domluc at gmail dot com
Status: Bogus
Bug Type: Strings related
Operating System: GNU/Linux Debian
PHP Version: 4.4.7
New Comment:
Ok,
I know way to do this,but, I think this is incorrect.
The auto cast trunk the variable without warning.
Previous Comments:
------------------------------------------------------------------------
[2007-07-05 14:28:11] pajoye@php.net
'==' will see the strings as numeric values, use === if you expect a
type safe comparison (as you noticed and documented).
------------------------------------------------------------------------
[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