php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44990 array('word')==array(0) -- true
Submitted: 2008-05-14 02:27 UTC Modified: 2013-02-14 17:16 UTC
From: design at apostolstudio dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.6 OS: Windows XP
Private report: No CVE-ID: None
 [2008-05-14 02:27 UTC] design at apostolstudio dot com
Description:
------------
array('word')==array(0) -- return true

Reproduce code:
---------------
if(array('word')==array(0)) echo "ERROR";

Actual result:
--------------
ERROR

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-05-14 02:39 UTC] cellog@php.net
use ===

'word' is converted to an integer for the comparison, and thus 0 == 0.

try this code:

if(array('word')===array(0)) echo "ERROR";
 [2008-05-14 02:58 UTC] design at apostolstudio dot com
Thanks for explanations.
 [2013-02-14 16:59 UTC] radamanf at gmail dot com
Comparison === needed ONLY if, during type conversion, we got same values, so String compare to Integer should be compared using Integer converted to string and check if they are equal. 

So if String is '' and Int is 0
or '1' == 1
'2' == 2
.. etc. only in this cases === is necessary to tell VARIABLE TYPE difference.

It's so obvious, why I'm explaining all this to you ?! You should know this better than me! Please fix this BUG
 [2013-02-14 17:16 UTC] nikic@php.net
@radamanf: He is comparing with == so all array elements are also compared with ==. And as in PHP 'word'==0 they are considered equal. Are you suggesting that when you compare arrays with == the elements should be compared with ===? That makes no sense to me.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed May 22 17:01:34 2019 UTC