Bug #51515 [Bgs]: Testing the equality of a string and an int can fails

From: Date: Thu, 08 Apr 2010 23:34:09 +0000
Subject: Bug #51515 [Bgs]: Testing the equality of a string and an int can fails
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-149426@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=51515&edit=1

 ID:               51515
 Updated by:       rasmus@php.net
 Reported by:      ianbara at imap dot cc
 Summary:          Testing the equality of a string and an int can fails
 Status:           Bogus
 Type:             Bug
 Package:          Scripting Engine problem
 Operating System: Ubuntu Linux
 PHP Version:      5.3.2

 New Comment:

Use === if you want to avoid type-juggling issues like this.  Still not
a bug.


Previous Comments:
------------------------------------------------------------------------
[2010-04-09 01:27:51] 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:05:23] 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-08 23:22:52] 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


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=51515&edit=1


Thread (4 messages)

« previous php.bugs (#149426) next »