> ## 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 Goto Statement

The `goto` statement is an unconditional control flow construct that immediately transfers program execution to a specific, named label within the same script and execution context.

## Syntax

The construct consists of two parts: the `goto` instruction followed by a target identifier, and the target label itself, which is defined by the identifier followed by a colon (`:`).

```php theme={"dark"}
goto TargetLabel;

// Intermediate statements are bypassed

TargetLabel:
// Execution resumes here
```

## Mechanics and Naming Rules

* **Label Identifiers:** A label name must follow standard PHP naming conventions for variables and functions. It must start with a letter or underscore, followed by any number of letters, numbers, or underscores (`[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*`).
* **Case Sensitivity:** Label names in PHP are case-sensitive. `goto MyLabel;` will not resolve to `mylabel:`.
* **Instruction Pointer:** When the Zend Engine encounters a `goto` statement, it moves the instruction pointer directly to the opcode associated with the target label, skipping all intermediate code.

## Scope and Limitations

PHP imposes strict lexical and contextual boundaries on the `goto` statement to prevent memory corruption and stack unwinding issues.

1. **Context Boundary:** You cannot jump into or out of a function or method. The `goto` statement and its target label must reside within the same local scope.
2. **File Boundary:** You cannot jump between different files. A `goto` cannot target a label inside an included or required file, nor can it jump out to a parent file.
3. **Control Structure Entry:** You cannot jump *into* any loop (`for`, `while`, `do-while`, `foreach`) or `switch` statement. Attempting to do so results in a fatal compilation error.
4. **Control Structure Exit:** You *can* jump *out of* a loop or `switch` statement.

## Code Examples

**Basic Execution Flow:**

```php theme={"dark"}
<?php
echo "Initialization\n";

goto jump_point;

echo "This statement is skipped entirely.\n";

jump_point:
echo "Execution resumed.\n";
?>
```

**Illegal Scope Jump (Fatal Error):**

```php theme={"dark"}
<?php
goto loop_body; // Fatal error: 'goto' into loop or switch statement is disallowed

for ($i = 0; $i < 10; $i++) {
    loop_body:
    echo $i;
}
?>
```

**Legal Control Structure Exit:**

```php theme={"dark"}
<?php
for ($i = 0; $i < 10; $i++) {
    for ($j = 0; $j < 10; $j++) {
        if ($i === 2 && $j === 5) {
            goto exit_nested_loops;
        }
    }
}

exit_nested_loops:
echo "Exited both loops.";
?>
```

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