php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41905 Incorrect String Compare with '=='
Submitted: 2007-07-05 14:20 UTC Modified: 2007-07-05 14:49 UTC
From: domluc at gmail dot com Assigned:
Status: Not a bug Package: Strings related
PHP Version: 4.4.7 OS: GNU/Linux Debian
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: domluc at gmail dot com
New email:
PHP Version: OS:

 

 [2007-07-05 14:20 UTC] 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!


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-07-05 14:28 UTC] 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:49 UTC] domluc at gmail dot com
Ok,

I know way to do this,but, I think this is incorrect.
The auto cast trunk the variable without warning.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 20:01:29 2024 UTC