PHP is_bool() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Variables

Definition

In PHP, is_bool() checks whether a variable is a boolean. It returns true only for the values true and false.

It tests the type, not the meaning of the value. The number 0 and the string "false" look like false, but they are not booleans, so is_bool() returns false for them. Comparisons such as 5 > 3 produce real booleans.

Syntax

Call is_bool() with the values you need. Start with this line.

PHP
$result = is_bool($value);
CallWhat it does
is_bool(true)Returns true, because the value is a boolean.
is_bool(0)Returns false, because 0 is an integer.
is_bool("false")Returns false, because it is a string.

To turn text such as "yes" or "off" into a real boolean, use filter_var() with FILTER_VALIDATE_BOOLEAN. To convert any value to a boolean, use boolval().

Library declarations
PHP
is_bool(mixed $value): bool

Parameters

ParameterDescription
valueRequired. The variable or value to test.

Return Value

Return ValueDescription
booltrue if the value is true or false, otherwise false.

PHP Examples

Example 1 — Booleans vs Look-Alikes

Check real booleans and a few values that only look like booleans.

PHP
<?php
var_dump(is_bool(true));
var_dump(is_bool(false));
var_dump(is_bool(0));
var_dump(is_bool("true"));

How It Works

  1. true is a real boolean, so the result is true.
  2. false is also a real boolean, so is_bool(false) is true. It does not mean the answer is false.
  3. 0 is an integer, so is_bool(0) is false.
  4. "true" in quotes is a string, so the result is false.

Example 2 — Results of Comparisons

Comparison and logical operators always return real booleans. Null and text do not.

PHP
<?php
var_dump(is_bool(5 > 3));
var_dump(is_bool(!0));
var_dump(is_bool("false"));
var_dump(is_bool(null));

How It Works

  1. 5 > 3 is a comparison, and it returns the boolean true.
  2. The ! operator always returns a boolean, so !0 is true.
  3. The text "false" is a string, not a boolean.
  4. null means no value, and it is not a boolean either.

Example 3 — Validating Yes/No Input

filter_var() can return a real boolean, or null when it does not understand the text. is_bool() tells you which one you got.

PHP
<?php
$inputs = ["yes", "off", "maybe"];

foreach ($inputs as $input) {
    $result = filter_var($input, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);

    if (is_bool($result)) {
        echo $input, " => ", $result ? "true" : "false", PHP_EOL;
    } else {
        echo $input, " => not a boolean", PHP_EOL;
    }
}

How It Works

  1. filter_var() with FILTER_VALIDATE_BOOLEAN understands words such as yes, on, true, no, off and false.
  2. FILTER_NULL_ON_FAILURE makes it return null instead of false when the text is not understood.
  3. is_bool() separates real answers (true or false) from the null failure case.
  4. "yes" gives true, "off" gives false, and "maybe" is rejected.

Frequently Asked Questions

is_bool() returns true if a variable holds the boolean value true or false, and false for every other type.
No. 0 is an integer, not a boolean. is_bool() checks the type, so only the values true and false give true.
is_bool() asks whether a value already is a boolean. boolval() converts any value into a boolean. For example, boolval(0) returns false, but is_bool(0) is false because 0 is not a boolean.
Use filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE). It returns true or false for known words and null for anything else.
is_bool() answers the question "is this a boolean?", not "is this true?". false is a boolean, so the answer is true.

Next: is_callable()

is_callable() checks whether a value can be called like a function. It returns true for fu.

is_callable() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful