> ## 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 Pre-Increment

The `++` operator is a unary mutating operator in PHP that increments the value of a variable by one. It directly modifies the operand in memory and evaluates to either the original or the incremented value, depending on its syntactic placement relative to the variable.

## Evaluation Modes

The operator functions in two distinct modes based on its position:

**1. Pre-increment (`++$variable`)**
The variable is incremented first, and the expression evaluates to the *new* mutated value.

```php theme={"dark"}
$x = 10;
$result = ++$x; 

// $x is mutated to 11
// $result is assigned 11
```

**2. Post-increment (`$variable++`)**
The expression evaluates to the *original* value of the variable, and the variable is incremented afterward.

```php theme={"dark"}
$y = 10;
$result = $y++; 

// $result is assigned 10
// $y is mutated to 11
```

## Type-Specific Behavior and Coercion

Unlike standard binary addition (`$var + 1`), the `++` operator does not strictly cast all types to integers or floats. It applies specific internal rules based on the operand's underlying `zval` type:

* **Integers and Floats:** Performs standard arithmetic incrementation.
* **Null:** Coerces the value to `1`.
* **Booleans:** The operator does not mutate the value (`true` remains `true`, and `false` remains `false`). As of PHP 8.3, applying the `++` operator to a boolean emits an `E_WARNING`.
* **Strings:** Behavior depends on the string's contents:
  * *Numeric strings:* Strings containing valid numeric values (e.g., `"5"`, `"5.5"`) are coerced into `int` or `float` types and incremented arithmetically (e.g., `"5"` becomes `int(6)`).
  * *Non-numeric strings:* Historically, PHP applies a Perl-style alphanumeric increment where characters carry over (e.g., `'a'` becomes `'b'`, `'Z'` becomes `'AA'`). As of PHP 8.3, applying the `++` operator to non-numeric strings is deprecated and emits an `E_DEPRECATED` notice.
* **Arrays:** Applying the `++` operator results in a `TypeError`.
* **Objects:** Applying the `++` operator to standard userland objects results in a `TypeError`. However, internal classes that support operator overloading at the engine level (such as `GMP` objects) can be successfully incremented.

## Internal Execution

At the compilation level, the Zend Engine translates the `++` operator into specific opcodes (`ZEND_PRE_INC` or `ZEND_POST_INC`). Because these opcodes are designed to mutate a variable's `zval` directly in place, the `++` operator requires a memory reference. It is strictly bound to variables and cannot be applied to literal values or expressions.

```php theme={"dark"}
// Valid: Applied to a variable reference
$a = 5;
$a++;

// Valid: Applied to an internal object supporting operator overloading
$gmp = gmp_init(5);
$gmp++;

// Invalid: Parse error: syntax error, unexpected integer "5", expecting variable
++5;

// Invalid: Parse error: syntax error, unexpected token "++"
(2 + 3)++;

// Invalid: Fatal error: Cannot use temporary expression in write context
[1, 2, 3][0]++;
```

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