Content · Programming · PHP

PHP get_included_files() Function: Usage and Examples

Lists file paths included by include or require during the current request.

1 views Published Oct 17, 2026 Updated Oct 17, 2026

get_included_files() Function is one of the PHP operations used in filesystem and stream workflows. Lists file paths included by include or require during the current request. The examples below show what it does and how to handle its result.

What Is get_included_files() Function?


Lists file paths included by include or require during the current request.

Its syntax is:

get_included_files()

This function or method takes no parameters.

Return value: The declared return type is array. The results include the main script and are not the same as a dependency lockfile.

Important: The results include the main script and are not the same as a dependency lockfile.

Example 1: Basic Usage


The basic example focuses on the behavior of get_included_files() Function: lists file paths included by include or require during the current request. Inputs are defined locally or shown as application-controlled paths.

<?php

print_r(get_included_files());

The displayed value, file content or return status depends on the input and surrounding environment. Results involving local paths, identifiers or generated files are not fixed values.

Example 2: A Different Use Case


This second example illustrates another input or execution condition for get_included_files() Function. Notice the different checks, arguments, or output handling.

<?php

$includedFiles = get_included_files();
foreach ($includedFiles as $includedFile) { echo basename($includedFile) . "\n"; }

This variation matters because the results include the main script and are not the same as a dependency lockfile.

Practical Example: Using the Operation in an Application


The following example demonstrates how get_included_files() Function fits into a more complete file or archive workflow, including inputs and appropriate checks.

<?php

$loadedFiles = get_included_files();
$uniqueDirectories = array_unique(array_map("dirname", $loadedFiles));
print_r($uniqueDirectories);

The operation shown is an illustrative script. Adapt the filenames, required permissions, and error handling to your own controlled application environment before running it.

Important Behavior and Edge Cases


  • Function behavior: Lists file paths included by include or require during the current request.
  • Limitation: The results include the main script and are not the same as a dependency lockfile.

Comparison With Related Functions


Function or MethodDifference
get_included_files() FunctionLists file paths included by include or require during the current request.
get_required_files()An exact alias of get_included_files() despite its name.

Use get_included_files() Function for the specific behavior described above. The related operation, get_required_files(), serves a different purpose; do not substitute it unless that different behavior is intended.

Common Beginner Mistakes


MistakeCorrect Approach
Assuming this operation has the same behavior on every file or environment.The results include the main script and are not the same as a dependency lockfile. Check prerequisites and return values before using the result.
Treating get_required_files() as an interchangeable replacement for get_included_files() Function.An exact alias of get_included_files() despite its name.

Key Takeaways


  • Lists file paths included by include or require during the current request.
  • The results include the main script and are not the same as a dependency lockfile.
  • Related operation: get_required_files() — An exact alias of get_included_files() despite its name.

get_included_files() Function is useful when its specific behavior matches your application requirement. Keep paths controlled, check failures, and handle environment-dependent operations deliberately.

Share this resourceSend this page to someone who may find it useful.