Bug #51795 [Bgs]: Loose comparison too loose

From: Date: Tue, 11 May 2010 23:27:20 +0000
Subject: Bug #51795 [Bgs]: Loose comparison too loose
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-150355@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=51795&edit=1

 ID:               51795
 Updated by:       rasmus@php.net
 Reported by:      slevinski at gmail dot com
 Summary:          Loose comparison too loose
 Status:           Bogus
 Type:             Bug
 Package:          Strings related
 Operating System: Ubuntu
 PHP Version:      5.2.13

 New Comment:

Or prefix your strings with 0x if you want to force hex.


Previous Comments:
------------------------------------------------------------------------
[2010-05-11 22:18:02] dtajchreber@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

"0080" turns into an 80 and is stored as an int. "80e0" turns into 80 x
10^0 which is also 80 but is stored as a float. 80(int) == 80(float).
80(int) !== 80(float). I didn't understand the rest of what you wrote
but php.net/hexdec might be of some use. 

See:
http://www.php.net/manual/en/language.types.string.php#language.types.string.conversion

------------------------------------------------------------------------
[2010-05-11 16:25:33] slevinski at gmail dot com

Description:
------------
if ("0080" == "80e0") echo "Smoking crack!";

I created a double octet coded character set.  I'm using 4 hex to
represent each character.  I'm using a switch statement to get a token
based on the value.  The string "80e0" is incorrectly setting off the
case "0080" statement.

The strict comparison of === works as expected, but the switch uses a
loose comparison.  

Test script:
---------------
if ("0080" == "80e0") {
  echo "Too loose";
} else {
  echo "Just right";
}

Expected result:
----------------
Just right

Actual result:
--------------
Too loose


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



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


Thread (3 messages)

« previous php.bugs (#150355) next »