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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Sat May 10 02:01:26 2025 UTC