> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# PHP bool

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.

```php theme={"dark"}
$valid = true;
$active = FALSE; // Case-insensitive, though lowercase is the PSR-12 standard
```

## 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.

```php theme={"dark"}
$explicitCast = (bool) $variable;
```

## 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`:

```php theme={"dark"}
(bool) false;     // The boolean false itself
(bool) 0;         // Integer zero
(bool) 0.0;       // Float zero (and -0.0)
(bool) "";        // Empty string
(bool) "0";       // String containing exactly the character "0"
(bool) [];        // Array with zero elements
(bool) null;      // NULL value (including unset variables)
```

*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:

```php theme={"dark"}
$trueStr = (string) true;   // Evaluates to the string "1"
$falseStr = (string) false; // Evaluates to an empty string ""

echo true;  // Outputs the string "1"
echo false; // Outputs an empty string ""
```

## 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 (`===` / `!==`).

```php theme={"dark"}
$var = false;
$intVar = 1;

// Checking type
is_bool($var);     // Returns true (it is of type bool)
is_bool($intVar);  // Returns false (it is an integer)

// Checking strict value
$var === false;    // Returns true (strict type and value check)
$intVar === true;  // Returns false (strict type and value check)

// Loose comparison
$intVar == true;   // Returns true (loose comparison triggers coercion)
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor PHP Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
