php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25943 String comparison with "if"
Submitted: 2003-10-22 01:07 UTC Modified: 2003-10-23 01:24 UTC
From: wolfgang dot wuensch at ww-informatik dot de Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.3.2 OS: Windows
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: wolfgang dot wuensch at ww-informatik dot de
New email:
PHP Version: OS:

 

 [2003-10-22 01:07 UTC] wolfgang dot wuensch at ww-informatik dot de
Description:
------------
I compare two strings, who are different from each other.

The if-Statement gives me a "true".

I want a "false".

Reproduce code:
---------------
$val1="020510010404020301";
$val2="020510010404020302";

if( $val1 == $val2  )
{
    echo $val1;
    echo "<br>";
    echo $val2;
    echo "<br>";
    echo "is not good";
}
else {
    echo "yeah";
}

Expected result:
----------------
go into the "else"

Actual result:
--------------
go into the "if"



Note:
var_dump() used with $var1 and $var2 gives me string(18)

strcmp() works fine.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-10-22 01:21 UTC] alan_k@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

php -r \'
$a = \"0205100104040203000000000000001\";
$b = \"0205100104040203000000000000002\";
var_dump($a == $b);\'
== true

php -r \'
$a = \"0205100104040203000000000000001\";
$b = \"0205100104040203000000000000002\";
var_dump($a === $b);\'
== false.

php will cast strings to numbers and compare them.. - depending on your system. the number may be too big to store in an double.. 
- use bcmath or === or strcmp...

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 08:01:29 2024 UTC