CascadiaPHP 2024


(PHP 4, PHP 5, PHP 7, PHP 8)

is_bool Finds out whether a variable is a boolean


is_bool(mixed $value): bool

Finds whether the given variable is a boolean.



The variable being evaluated.

Return Values

Returns true if value is a bool, false otherwise.


Example #1 is_bool() examples

= false;
$b = 0;

// Since $a is a boolean, it will return true
if (is_bool($a) === true) {
"Yes, this is a boolean";

// Since $b is not a boolean, it will return false
if (is_bool($b) === false) {
"No, this is not a boolean";

See Also

  • is_float() - Finds whether the type of a variable is float
  • is_int() - Find whether the type of a variable is integer
  • is_string() - Find whether the type of a variable is string
  • is_object() - Finds whether a variable is an object
  • is_array() - Finds whether a variable is an array

add a note

User Contributed Notes 2 notes

5 years ago
It should be stated that this function returns true if the _type_ of it's argument is boolean. It does not convert or coerce the value to a boolean type, not sure why so many comments focus on how to do this.
However, if you arrived here looking for a solution to convert a value to a boolean type, use this:

to_bool($x) { return (bool)$x; }
Julio Marchi
4 years ago
To check if a variable is boolean is one thing, to evaluate if the value of a variable represents a boolean condition (true or false) is another.

Here is a simple function that checks the status of the received variable in regard to boolean equivalencies (case-insensitive).

* Check "Booleanic" Conditions :)
* @param [mixed] $variable Can be anything (string, bol, integer, etc.)
* @return [boolean] Returns TRUE for "1", "true", "on" and "yes"
* Returns FALSE for "0", "false", "off" and "no"
* Returns NULL otherwise.
function is_enabled($variable)
if (!isset(
$variable)) return null;

Of course, it is a simplistic approach, but for the majority of cases it will do the job right.

And, just to put the thing from the right perspective, here's a real function that does what Phill disclosed:

* Convert $variable to boolean (adapted from Phill answer)
* @param [mixed] $variable Can be anything
* @return [boolean] Returns the booelan equivalent to $variable based on Zend Enegine interpretation
function to_bool($variable)
return (bool)

I hope it helps someone. Happy coding.
To Top