> ## 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 Right Shift

The `>>` operator is the bitwise right shift operator in PHP. It shifts the binary representation of the left operand to the right by the number of bit positions specified by the right operand.

```php theme={"dark"}
$result = $value >> $steps;
```

## Technical Mechanics

1. **Type Casting:** PHP automatically casts both `$value` and `$steps` to integers before performing the bitwise operation. Floating-point numbers are truncated.
2. **Arithmetic Shift:** PHP implements an *arithmetic* right shift, meaning it preserves the sign bit (the most significant bit). PHP does not have a logical (zero-fill) right shift operator.
3. **Bit Discarding:** Bits shifted past the least significant bit (position 0) are permanently discarded.
4. **Sign Extension:** Vacated bit positions on the left (the most significant side) are filled with the original sign bit. They are filled with `0` for positive integers and `1` for negative integers (which are represented in two's complement).
5. **Mathematical Equivalence:** Shifting an integer right by `$n` positions is mathematically equivalent to integer division by $2^n$, rounded towards negative infinity: `floor($value / (2 ** $steps))`.

## Syntax Visualization

**Positive Integer Shift:**

```php theme={"dark"}
$a = 12;       // Binary: 00000000 ... 00001100
$b = $a >> 2;  // Binary: 00000000 ... 00000011 (Decimal: 3)

// The two rightmost bits (00) are discarded.
// Two 0s are shifted in from the left.
```

**Negative Integer Shift:**

```php theme={"dark"}
$x = -12;      // Binary: 11111111 ... 11110100 (Two's complement)
$y = $x >> 2;  // Binary: 11111111 ... 11111101 (Decimal: -3)

// The two rightmost bits (00) are discarded.
// Two 1s are shifted in from the left to preserve the negative sign.
```

## Edge Cases and Constraints

* **Negative Shift Steps:** Attempting to shift by a negative number of steps (`$value >> -1`) throws an `ArithmeticError` in PHP 7.0 and later.
* **Overshifting:** Shifting by an amount greater than or equal to the bit width of the system's integer type (typically 64 bits) results in undefined behavior. PHP inherits this behavior directly from C and does not implement software checks to zero out the result. On most modern architectures (such as x86\_64), the CPU masks the shift amount modulo the bit width. Consequently, shifting a 64-bit integer by 64 positions (`$value >> 64`) is evaluated by the hardware as `$value >> (64 % 64)`, which equals `$value >> 0`. This typically returns the original `$value` rather than `0` or `-1`.
* **String Operands:** If strings are passed to the operator, PHP attempts to convert them to integers. If the string is non-numeric, a `TypeError` is thrown in PHP 8.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>
