Rather than having to use an include a statement to include every new PHP file I add to a directory, is there a way to tell PHP to just load all files in a directory. Some kind of recursive call to load everything.
1 Answer
There is no recursive version of an include statement but it is quite simple to do this using code. I would discourage this sort of thing though. If you dropped a file in that had an error, it would break the entire script as there would be no way to only include this file if the code was running in debug mode or something. The code below will do what you are looking to do but use it with caution as this automation comes with some risks to it. You might save having to copy and paste a line of code but it makes debugging code a lot harder and risks bugs being introduced simply from dropping a file in a directory. You might want to use some better error handling to ensure that a file with some syntax errors is not included.
foreach (glob(dirname(__FILE__) ."/foldername/*.php") as $filename)
{
include $filename;
}

Related Questions
XML Signature Verifier
Voltage Divider Calculator
SSL Certificate Decoder
SQL Formatter
Online Font Playground to Test Google or Custom Fonts
File Hash Generator Online – Get Instant MD5 and SHA-256 Hashes