Bug #52372 [Opn->Bgs]: Comparison variable type logic
| From: | rasmus@php.net | Date: | Sun, 18 Jul 2010 23:54:39 +0000 |
| Subject: | Bug #52372 [Opn->Bgs]: Comparison variable type logic | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-152510@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=52372&edit=1
ID: 52372
Updated by: rasmus@php.net
Reported by: imagine7xy at gmail dot com
Summary: Comparison variable type logic
-Status: Open
+Status: Bogus
Type: Bug
Package: Scripting Engine problem
Operating System: Windows 7
PHP Version: 5.3.2
New Comment:
Yup.
if($string) evaluates to true if the string is not empty. If you want a
strict
typed comparison to true, use if($string===true)
Previous Comments:
------------------------------------------------------------------------
[2010-07-19 00:52:57] imagine7xy at gmail dot com
Description:
------------
Pretty self explanatory code, is this how PHP is supposed to behave?
Test script:
---------------
<?php
// outputs string instead of else?
$foo = true;
if ($foo == false) {
echo "not";
} elseif ($foo == "string") {
echo "string";
} else {
echo "else";
}
?>
Expected result:
----------------
output of "else"
Actual result:
--------------
output of "string"
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=52372&edit=1