> ## 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 Include Once Statement

The `include_once` statement is a PHP language construct that evaluates and incorporates a specified file into the current script during execution. It differs from the standard `include` statement by maintaining an internal registry of included files; before attempting an inclusion, PHP verifies if the file has already been loaded during the current request. If it has, PHP bypasses the operation, preventing fatal errors caused by duplicate declarations of functions, classes, or interfaces.

## Syntax

Because `include_once` is a language construct and not a standard function, parentheses are optional.

```php theme={"dark"}
include_once 'path/to/file.php';

// Parentheses are permitted but generally discouraged for language constructs
include_once('path/to/file.php'); 
```

## Execution Mechanics

**Path Resolution**
PHP resolves the target file path based on the `include_path` directive defined in `php.ini`. If the file is not found within the `include_path`, PHP falls back to checking the directory of the calling script, followed by the current working directory. Absolute paths and explicitly relative paths (those starting with `./` or `../`) bypass the `include_path` resolution entirely.

**Error Handling**
If PHP cannot locate or access the specified file, `include_once` emits an `E_WARNING` and allows script execution to continue. This contrasts with `require_once`, which emits an `E_WARNING` for the failed stream open followed by a fatal `E_COMPILE_ERROR` that halts script execution entirely. Because `require_once` emits a compile error rather than throwing an `Error` exception, the failure cannot be caught using a `try...catch` block.

**Return Values**
The construct evaluates to different values based on the inclusion state:

* **Initial Success:** Returns `1` by default. If the included file contains a `return` statement in the global scope, `include_once` evaluates to that specific returned value.
* **Already Included:** Returns boolean `true` if the file was previously included during the current request.
* **Failure:** Returns boolean `false` if the file cannot be found or read.

```php theme={"dark"}
// Assuming 'config.php' returns an array: return ['debug' => true];
$config = include_once 'config.php'; // $config is ['debug' => true]

// Subsequent call during the same request
$status = include_once 'config.php'; // $status is true (boolean)
```

## Scope Inheritance

When a file is included, the code within it inherits the variable scope of the exact line where the `include_once` statement is executed.

* **Variables:** Any variables available at the invocation line in the calling file are accessible within the included file. If `include_once` is called within a function, the included code behaves as if it were defined inside that function, restricting its variables to that local scope.
* **Functions and Classes:** Regardless of where the `include_once` statement is executed (even within a local function scope), all functions and classes defined within the included file are automatically injected into the global scope.
* **Magic Constants:** Magic constants like `__FILE__` and `__DIR__` evaluated inside the included file will resolve to the path and directory of the *included* file, not the calling file.

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