Bug #53487 [Bgs]: (integer) 0 == '_'
| From: | rasmus@php.net | Date: | Mon, 06 Dec 2010 17:34:38 +0000 |
| Subject: | Bug #53487 [Bgs]: (integer) 0 == '_' | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-156799@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=53487&edit=1
ID: 53487
Updated by: rasmus@php.net
Reported by: kherrera at codealchemy dot com
Summary: (integer) 0 == '_'
Status: Bogus
Type: Bug
Package: Scripting Engine problem
Operating System: Windows XP SP3
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Types matter. What is the integer value of '_' ? When you are
comparing
different types, one will be cast to the other. When you cast '_' to an
integer
you get 0. You either need to force both parameters to be of the same
type
yourself, or you need to use ===
Previous Comments:
------------------------------------------------------------------------
[2010-12-06 18:23:55] kherrera at codealchemy dot com
That's what I'm doing now, but why is this being flagged as bogus?
Zero is not equal to an underscore, typed or not.
------------------------------------------------------------------------
[2010-12-06 18:07:50] pajoye@php.net
use ===. and try echo (int) '_';
------------------------------------------------------------------------
[2010-12-06 17:45:20] kherrera at codealchemy dot com
Description:
------------
When testing the expression of integer "0" (zero) equals "_"
(underscore), the
result of the expression is true, when it should be false.
I could not select the proper PHP version number because it was not
listed:
C:>php -v
PHP 5.3.2 (cli) (built: Mar 3 2010 20:36:54)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans
Test script:
---------------
<?php
$index = 0;
if ( $index == '_' )
echo "Bug found.\n";
else
echo "No bug found.\n";
Expected result:
----------------
No bug found.
Actual result:
--------------
Bug found.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=53487&edit=1