|  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
 [2003-10-22 01:07 UTC] wolfgang dot wuensch at ww-informatik dot de
I compare two strings, who are different from each other.

The if-Statement gives me a "true".

I want a "false".

Reproduce code:

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"

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

strcmp() works fine.


Add a Patch

Pull Requests

Add a Pull Request


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

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-2023 The PHP Group
All rights reserved.
Last updated: Mon Dec 11 04:01:27 2023 UTC