php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51515 Testing the equality of a string and an int can fails
Submitted: 2010-04-08 23:22 UTC Modified: 2010-04-09 01:34 UTC
From: ianbara at imap dot cc Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3.2 OS: Ubuntu Linux
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: ianbara at imap dot cc
New email:
PHP Version: OS:

 

 [2010-04-08 23:22 UTC] ianbara at imap dot cc
Description:
------------
The attached code prints out EQUALS for me. It should not do this. === Does work 
correctly however.

Test script:
---------------
<?php

$old = "fca4ed9b761ca8ad209293248c2cdb56"; 
$new = 0;

if ($old == $new)
   echo "EQUALS";
else
   echo "NOT EQUALS"

?>

Expected result:
----------------
NOT EQUALS

Actual result:
--------------
EQUALS

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-04-09 01:05 UTC] felipe@php.net
-Status: Open +Status: Bogus
 [2010-04-09 01:05 UTC] felipe@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 [2010-04-09 01:27 UTC] ianbara at imap dot cc
Consider the below code, which returns "EQUALS, NOT EQUALS". If not a bug 
exactly, surely this is not optimal behavior for a language. 

<?php

$old_bad = "fca4ed9b761ca8ad209293248c2cdb56"; 
$old_good = "4ed9b761ca8ad209293248c2cdb56"; 
$new = 0;

if ($old_bad == $new) {
   echo "EQUALS, ";
 } else {
   echo "NOT EQUALS, ";
}

if ($old_good == $new) {
   echo "EQUALS\n";
 } else {
   echo "NOT EQUALS\n";
}

?>
 [2010-04-09 01:34 UTC] rasmus@php.net
Use === if you want to avoid type-juggling issues like this.  Still not a bug.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 00:01:31 2025 UTC