#25943 [Opn->Bgs]: String comparison with "if"
| From: | alan_k@php.net | Date: | Wed, 22 Oct 2003 05:21:13 +0000 |
| Subject: | #25943 [Opn->Bgs]: String comparison with "if" | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-49316@lists.php.net to get a copy of this message | ||
ID: 25943
Updated by: alan_k@php.net
Reported By: wolfgang dot wuensch at ww-informatik dot de
-Status: Open
+Status: Bogus
Bug Type: Scripting Engine problem
Operating System: Windows
PHP Version: 4.3.2
New Comment:
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...
Previous Comments:
------------------------------------------------------------------------
[2003-10-22 01:07:24] 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.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=25943&edit=1