php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54592 is_bool provides wrong result when running inside a switch
Submitted: 2011-04-22 16:39 UTC Modified: 2011-04-22 17:00 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: kadmio007 at hotmail dot com Assigned:
Status: Not a bug Package: Variables related
PHP Version: Irrelevant OS: Ubuntu Linux 10.10
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: kadmio007 at hotmail dot com
New email:
PHP Version: OS:

 

 [2011-04-22 16:39 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-04-22 17:00 UTC] dtajchreber@php.net
-Status: Open +Status: Bogus
 [2011-04-22 17:00 UTC] dtajchreber@php.net
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));
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jun 03 03:01:26 2025 UTC