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

The `void` keyword in PHP is a return type declaration introduced in PHP 7.1 that explicitly indicates a function or method does not return a value to its caller. When a function is typed with `void`, the PHP engine enforces strict rules regarding the `return` statement within that function's local scope.

```php theme={"dark"}
function identifier(): void {
    // execution block
}
```

## Syntactic Rules and Behavior

**Permitted Return Mechanisms**
A function declared with a `void` return type is restricted to two permitted return mechanisms (though execution may also terminate by throwing an `Exception` or halting the script via `exit()` or `die()`):

1. **Implicit return:** Reaching the end of the function block without encountering a `return` statement.
2. **Explicit empty return:** Using the `return;` statement without an accompanying expression.

```php theme={"dark"}
// Valid: Implicit return
function executeTask(): void {
    $operation = 2 + 2;
}

// Valid: Explicit empty return
function terminateEarly(bool $condition): void {
    if ($condition) {
        return; 
    }
    $operation = 2 + 2;
}
```

**Prohibited Return Statements**
Attempting to return any value from a `void` function results in a `Fatal error: A void function must not return a value`. This strictness extends to `null`. While a standard PHP function without a return type implicitly evaluates to `null`, a `void` function explicitly forbids the statement `return null;`.

```php theme={"dark"}
// Invalid: Triggers Fatal error
function returnString(): void {
    return "string"; 
}

// Invalid: Triggers Fatal error
function returnNull(): void {
    return null; 
}
```

## Type System Restrictions

* **Scope of Usage:** The `void` type is exclusively a return type. It cannot be used as a parameter type declaration or a class property type declaration. Attempting to do so will result in a parse error.
* **Union and Intersection Types:** `void` cannot be combined with other types. Declarations such as `void|string` or `?void` are syntactically invalid. The `void` type inherently represents the absence of a value, making it mutually exclusive with any type that represents a value.

## Inheritance and Variance

In object-oriented PHP, return types are covariant. When a parent class method declares a `void` return type, an overriding method in a child class is strictly limited in how it can alter this signature:

* The child method must declare a `void` return type, **or** (as of PHP 8.1) it may declare a `never` return type. Because `never` is a bottom type in PHP's type system, it is a valid subtype of `void`.
* A child class cannot widen the return type to omit `void`, nor can it change it to a specific value-bearing type like `mixed`, `int`, or `null`.

```php theme={"dark"}
class ParentClass {
    public function process(): void {}
}

class ChildClass extends ParentClass {
    // Valid: Exact match
    public function process(): void {}
}

class SubtypeChildClass extends ParentClass {
    // Valid (PHP 8.1+): 'never' is a bottom type and a valid subtype of 'void'
    public function process(): never {
        throw new RuntimeException('Halted');
    }
}

class InvalidChildClass extends ParentClass {
    // Invalid: Fatal error (Declaration must be compatible)
    public function process(): int {
        return 1;
    }
}
```

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