Bug #54592 [Opn->Bgs]: is_bool provides wrong result when running inside a switch

From: Date: Fri, 22 Apr 2011 15:00:52 +0000
Subject: Bug #54592 [Opn->Bgs]: is_bool provides wrong result when running inside a switch
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-160335@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=54592&edit=1 ID: 54592 Updated by: dtajchreber@php.net Reported by: kadmio007 at hotmail dot com Summary: is_bool provides wrong result when running inside a switch -Status: Open +Status: Bogus Type: Bug Package: Variables related Operating System: Ubuntu Linux 10.10 PHP Version: Irrelevant Block user comment: N Private report: N New Comment: Not quite... is_bool($var) evaluates to true; $var is false... false doesn't match that case. is_numeric($var) evaluates to false. $var == is_numeric($var) hence 'number' is printed. Another view: var_dump($var != is_bool($var)); var_dump($var == is_numeric($var)); Previous Comments: ------------------------------------------------------------------------ [2011-04-22 16:39:36] kadmio007 at hotmail dot com Description: ------------ Whenever testing for a variable with the value false using is_bool inside a switch statement will return false instead of true. I have tested it with different php versions, it happened on all of them. Test script: --------------- echo phpversion(); $var = false; switch ($var) { case is_bool($var): echo "boolean"; break; case is_numeric($var): echo "number"; break; } if (is_bool($var)) echo "boolean"; elseif (is_numeric($var)) echo "number"; Expected result: ---------------- 5.3.4booleanboolean Actual result: -------------- 5.3.4numberboolean ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=54592&edit=1

« previous php.bugs (#160335) next »