Get All Included Files in PHP

Want to know how many files are included in the current PHP script? Multiple files can be included in a single include file on a PHP script using include(), include_once(), require() and require_once().
- A.php
includes B.php
includes C.php, D.php etc

Now, file1.php can have multiple files and few of those file can also have included files. So, it may be difficult to know how many files are included in current script.

PHP has a built-in function for this. The function name is get_included_files().
It returns an array of files included.

$filesIncluded = get_included_files();
foreach ($filesIncluded as $fileName)
     echo $fileName . '<br>';

Now, you will get all files included in the script. get_required_files() is an alias of get_included_files() PHP function.

Check if file is included: To check if file is included or not in your php script, you can search in the array returned from get_included_files() function.

How to set included path (~ default path) for include file?

Comments are open for an year period. Please, write here on Facebook page.