> ## 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 Unary Plus

The `+` operator in PHP functions as both a unary identity operator for numeric type coercion and a polymorphic binary operator for arithmetic addition and array union. Unlike languages that overload the `+` symbol for string concatenation, PHP strictly isolates its behavior to mathematical evaluation and array key merging.

## Unary Identity Operator

When applied to a single operand, the `+` operator acts as the identity operator. Its primary mechanical function is to coerce scalar values into an `int` or `float` type.

```php theme={"dark"}
+$operand
```

**Type Resolution and Coercion:**

* **Numeric Types:** If the operand is already an `int` or `float`, the value and type are returned unchanged.
* **Numeric Strings:** If the operand is a string containing a valid numeric representation, the Zend Engine coerces it to an `int` or `float` based on the presence of a decimal or scientific notation.
* **Booleans:** `true` is coerced to `int(1)` and `false` is coerced to `int(0)`.
* **Invalid Types:** Applying the unary `+` to a non-numeric string, array, or object results in a `TypeError` in PHP 8.0 and later.

```php theme={"dark"}
$a = +"123";    // int(123)
$b = +"12.5";   // float(12.5)
$c = +true;     // int(1)
$d = +"1e3";    // float(1000)
```

## Binary Arithmetic Addition

When evaluating two scalar values, the `+` operator calculates the mathematical sum of the operands.

```php theme={"dark"}
$leftOperand + $rightOperand
```

**Type Resolution and Coercion:**

* **Integer + Integer:** Returns an `int`. If the resulting sum exceeds the system's `PHP_INT_MAX` threshold, the return type is automatically promoted to a `float` (integer overflow).
* **Float + Float / Mixed Numeric:** If either operand is a `float`, the return type is evaluated as a `float`.
* **Numeric Strings:** If an operand is a numeric string, PHP's type juggling coerces it to an `int` or `float` before evaluation.

```php theme={"dark"}
$a = 10 + 20;         // int(30)
$b = 10.5 + 2;        // float(12.5)
$c = "5" + 10;        // int(15) - String coerced to int
$d = PHP_INT_MAX + 1; // float(...) - Integer overflow promotion
```

## Binary Array Union

When both operands are composite array types, the `+` operator acts as the union operator. It appends the elements of the right-hand array into the left-hand array based on their keys.

```php theme={"dark"}
$leftArray + $rightArray
```

**Key Collision Resolution:**
During an array union, the left-hand array takes absolute precedence. If a string or integer key exists in the left operand, the corresponding key-value pair in the right operand is entirely ignored. The operator does not recursively merge nested arrays, nor does it re-index numeric keys.

```php theme={"dark"}
$left  = ['a' => 1, 'b' => 2];
$right = ['b' => 99, 'c' => 3];

$result = $left + $right;
/*
array(3) {
  ["a"] => int(1)
  ["b"] => int(2)   // The left-hand value is preserved; 99 is discarded.
  ["c"] => int(3)
}
*/
```

## Invalid Operand Combinations

Applying the binary `+` operator to incompatible types (e.g., attempting to add an `array` to an `int`, or an `object` to a `float`) violates PHP's strict typing rules for this operator. In PHP 8.0+, this results in a fatal `TypeError`.

```php theme={"dark"}
$invalid = ['a' => 1] + 5; 
// Fatal error: Uncaught TypeError: Unsupported operand types: array + int
```

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