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

The `+` operator in PHP is a polymorphic operator that functions as an arithmetic addition operator for numeric types, an array union operator for arrays, and a unary identity operator for numeric casting. Its execution behavior and return type are strictly determined by the data types of the operands evaluated at runtime.

## Arithmetic Addition (Binary)

When applied to numeric operands, the `+` operator performs standard arithmetic addition.

```php theme={"dark"}
$result = $expression1 + $expression2;
```

**Type Resolution and Coercion:**

* **Integer + Integer:** Returns an `int`. If the resulting value exceeds `PHP_INT_MAX` (integer overflow) or falls below `PHP_INT_MIN` (integer underflow), PHP automatically promotes the return type to a `float`.
* **Integer + Float (or Float + Float):** Returns a `float`. The integer operand is implicitly widened to a float before the operation occurs.
* **Numeric Strings:** If an operand is a string containing a valid numeric representation (e.g., `"42"` or `"3.14"`), PHP implicitly coerces it to an `int` or `float`.
* **Non-Numeric Strings:** In PHP 8.0 and later, applying the `+` operator to a non-numeric string throws a `TypeError`. In PHP 7.1 through 7.4, it emitted a `Warning` and cast the string to `0`. In PHP 7.0 and earlier, it performed the cast to `0` silently without emitting any warning or notice.

## Array Union (Binary)

When both operands are arrays, the `+` operator acts as the union operator.

```php theme={"dark"}
$result = $arrayLeft + $arrayRight;
```

**Evaluation Mechanics:**

* The operator appends the elements of the right-hand array to the left-hand array.
* **Key Collisions:** If a string or integer key exists in both arrays, the value from the left-hand array is preserved, and the corresponding key-value pair from the right-hand array is entirely ignored.
* **Index Preservation:** Unlike functions such as `array_merge()`, the `+` operator does *not* re-index numeric keys. The original keys from both arrays are strictly maintained.

## Unary Identity (Unary)

When used as a prefix to a single operand, the `+` operator acts as a unary identity operator.

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

**Evaluation Mechanics:**

* It performs an explicit type conversion, casting the operand to an `int` or `float` depending on the operand's underlying value.
* If the operand is already a numeric type, it returns the value unmodified.
* If the operand is a numeric string, it resolves to the corresponding numeric type.

## Strict Typing Independence

The `+` operator is completely unaffected by the `declare(strict_types=1);` directive. It consistently performs standard type juggling (such as coercing numeric strings to numbers) regardless of the strict typing context. Any `TypeError` associated with strict typing is triggered by function boundary type checks—either evaluating the arguments before the operator executes or evaluating the result afterward—and never by the `+` operator itself.

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