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

The `require_once` statement is a PHP language construct that includes and evaluates a specified file during script execution, with the strict condition that the file is parsed only once per execution cycle. If the specified file cannot be found or read, the Zend Engine triggers a fatal `E_COMPILE_ERROR` and immediately halts script execution.

## Syntax

Because `require_once` is a language construct and not a standard function, parentheses are optional. Omitting them is the standard convention.

```php theme={"dark"}
// Standard syntax
require_once 'path/to/file.php';

// Valid, but generally discouraged syntax
require_once('path/to/file.php');

// Assigning a return value from the included file
$result = require_once 'path/to/file.php';
```

## Execution Mechanics

**Internal Registry Checking**
When `require_once` is invoked, PHP resolves the absolute path of the target file (resolving any symbolic links) and checks it against its internal registry of previously included files. This registry can be inspected during runtime using the `get_included_files()` function. If the resolved path exists in this registry, PHP bypasses the inclusion process entirely.

**Path Resolution**
Path resolution behavior depends strictly on the format of the provided string. If an absolute path or an explicit relative path (starting with `./` or `../`) is provided, PHP resolves the path directly and completely bypasses the `include_path` directive. The `include_path` directive is only searched when an *unqualified* relative path is provided (e.g., `require_once 'file.php';`). If an unqualified 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.

**Scope Inheritance**
The code within the included file inherits the variable scope of the exact line where the `require_once` statement occurs. Any variables available at that line in the calling file will be available within the included file. However, functions and classes defined in the included file are placed into the global scope.

## Return Values

The `require_once` construct evaluates to a specific value based on the execution state:

* **Successful First Inclusion:** Returns `1` by default.
* **Explicit Return:** If the included file contains a `return` statement in its global scope, `require_once` evaluates to that specific returned value.
* **Subsequent Calls:** If the file has already been included earlier in the execution lifecycle, `require_once` returns boolean `true` and does not re-execute the file.

## Compilation Overhead

Because `require_once` must perform absolute path resolution and check the internal inclusion registry to guarantee uniqueness, it incurs a marginal performance overhead compared to the standard `require` statement. The engine must ensure that two different relative paths pointing to the same physical file are recognized as identical to prevent duplicate compilation.

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