php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53429 comparing the integer 0 "Zero" with any other string always returns true
Submitted: 2010-11-30 18:30 UTC Modified: 2010-11-30 19:03 UTC
Votes:3
Avg. Score:4.7 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:2 (100.0%)
From: claudsan at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.3.3 OS: Windows 7
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: claudsan at gmail dot com
New email:
PHP Version: OS:

 

 [2010-11-30 18:30 UTC] claudsan at gmail dot com
Description:
------------
comparing the integer 0 "Zero" with any other string always returns null

Test script:
---------------
$x =(int) 0;
if($x == 'foo')
echo "Zero is foo";

//or

var_dump($x == 'foo');


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-11-30 18:32 UTC] claudsan at gmail dot com
-Summary: comparing the integer 0 "Zero" with any other string always returns null +Summary: comparing the integer 0 "Zero" with any other string always returns true
 [2010-11-30 18:32 UTC] claudsan at gmail dot com
comparing the integer 0 "Zero" with any other string always returns true
 [2010-11-30 19:03 UTC] rasmus@php.net
-Status: Open +Status: Bogus
 [2010-11-30 19:03 UTC] rasmus@php.net
What is the integer value of the string "foo" ?  When you are using a loosely 
typed language you have to understand that there will be type juggling when you 
try to compare an integer to a string.  If you want a strict comparison, use ===.
 [2010-11-30 19:11 UTC] claudsan at gmail dot com
Ok entendi que todas as strings quando convertidas para integer recebe o valor 0 "zero", nestas situações realmente deve se utilizar o sinal ===

Obrigado.
 [2010-11-30 19:12 UTC] claudsan at gmail dot com
Ok I understand that all strings when converted to integer assigned the value 0 "zero" in these situations really should use the sign ===

Thanks.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 14 14:01:31 2025 UTC