php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65551 Compare 0 variable alway return true
Submitted: 2013-08-25 16:39 UTC Modified: 2013-08-25 16:46 UTC
From: nukboon at gmail dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.5.3 OS: Centos 6
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: nukboon at gmail dot com
New email:
PHP Version: OS:

 

 [2013-08-25 16:39 UTC] 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)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-08-25 16:46 UTC] rasmus@php.net
-Status: Open +Status: Not a bug
 [2013-08-25 16:46 UTC] rasmus@php.net
You are mixing types, so type-juggling comes into effect. (int)'id' is 0 and thus 
0==0. Read http://php.net/juggling
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat May 03 15:01:28 2025 UTC