Bug #65551 [Opn->Nab]: Compare 0 variable alway return true
| From: | rasmus@php.net | Date: | Sun, 25 Aug 2013 16:46:15 +0000 |
| Subject: | Bug #65551 [Opn->Nab]: Compare 0 variable alway return true | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-181184@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=65551&edit=1
ID: 65551
Updated by: rasmus@php.net
Reported by: nukboon at gmail dot com
Summary: Compare 0 variable alway return true
-Status: Open
+Status: Not a bug
Type: Bug
Package: Unknown/Other Function
Operating System: Centos 6
PHP Version: 5.5.3
Block user comment: N
Private report: N
New Comment:
You are mixing types, so type-juggling comes into effect. (int)'id' is 0 and thus
0==0. Read http://php.net/juggling
Previous Comments:
------------------------------------------------------------------------
[2013-08-25 16:39:20] nukboon at gmail dot com
Description:
------------
See below my testing script. I've test with all version of php it's return same
result.
Test script:
---------------
$a = 0;
if($a == 'id'){
echo 'Yes' . PHP_EOL;
}
var_dump($a);
var_dump($a == 'id');
var_dump($a == 'ids');
var_dump($a == 'def');
$a = 1;
if($a == 'id'){
echo 'Yes' . PHP_EOL;
}
var_dump($a);
var_dump($a == 'id');
var_dump($a == 'ids');
var_dump($a == 'def');
// Result
Yes
int(0)
bool(true)
bool(true)
bool(true)
int(1)
bool(false)
bool(false)
bool(false)
Expected result:
----------------
$a = 0;
var_dump($a == 'abc');
//should be: bool(false)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=65551&edit=1