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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: bo0rsh201 at gmail dot com
New email:
PHP Version: OS:

 

 [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: Tue May 21 15:01:34 2024 UTC