I want to simplify files including or requiring process in PHP a little bit, so I wrote the function:
$files = array("filename", "other_filename");
function required_files($filenames) {
foreach ($filenames as $filename) {
require_once("admin/files/".$filename.".php");
}
}
required_files($files);
It doesn't work unfortunately, but I know it's being processed by PHP, because whenever I change the "filename" to a name of the file, which doesn't exist, I got the error about that file is not existent. What am I doing wrong here?
PS: I tried to echo
or return
require_once()
but no effect.
That's within Wordpress template's functions.php.
It seems that what you want is not possible, at least not without declaring all the variables in the included files global (which is probably a bad idea).
While this question is not an exact duplicate, the answers to what (I think) is really being asked can be found on SO here and here.
If the project is object oriented, using an autoloader is a good alternative approach, but unviable of course if the code is written in procedural style.