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
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: 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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 09 16:02:26 2025 UTC