php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62722 incorrect comparison result
Submitted: 2012-08-02 06:59 UTC Modified: 2012-08-02 07:03 UTC
From: bo0rsh201 at gmail dot com Assigned:
Status: Not a bug Package: Variables related
PHP Version: 5.4.5 OS: Win7
Private report: No CVE-ID: None
 [2012-08-02 06:59 UTC] bo0rsh201 at gmail dot com
Description:
------------
comparision of integer 0 and any string always returns true
the problem is independent from operands order.

Test script:
---------------
<?php
// the following code returns true
var_dump(('hello world' == 0));
// the same thing
var_dump((0 == 'hello world'));


Expected result:
----------------
I think it has to return false, matching inequal variables


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-08-02 07:03 UTC] rasmus@php.net
-Status: Open +Status: Not a bug
 [2012-08-02 07:03 UTC] rasmus@php.net
'1'==1
That is, (int)'1' == 1
So (int)'hello world' == 0
it is consistent
Weak typing means there will be type juggling when you compare different types.
Use === if you want to prevent type juggling.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 22 01:01:31 2024 UTC