Skip to main content
A bool (boolean) is a scalar data type in PHP that represents a logical truth value, strictly capable of holding one of two states: true or false. The boolean constants in PHP are case-insensitive.

Type Casting and Coercion

PHP is a dynamically typed language and frequently performs implicit boolean coercion during logical operations. Explicit casting is executed using the (bool) or (boolean) cast operators.

Falsy Values

When a value is implicitly coerced or explicitly cast to a bool, PHP evaluates most values as true (truthy), with a specific set of exceptions that evaluate to false (falsy). The following standard values evaluate to false:
Note: While almost all other values evaluate to true (including the string "false", the string "0.0", negative integers, and empty stdClass objects), there are exceptions for internal objects that overload their casting behavior. For example, a SimpleXMLElement object created from an empty XML element without attributes evaluates to false.

String Representation

When a bool is cast to a string—such as when passed to an echo or print statement—PHP handles the conversion asymmetrically:

Type Checking

To verify if a variable is strictly of the bool type without triggering implicit type coercion, use the built-in is_bool() function. To verify if a variable holds a specific boolean value without coercion, use the strict comparison operators (=== / !==).
Tired of Poor PHP Skills? Fix That With Deep Grasping!Learn More