I have designed a custom include function for my application, which was meant to make my life much easier except it's done the complete opposite and has resulted in me debugging the same type of errors for hours until this lightbulb moment realising what it was.
Because the files are being included into a function, the variables, functions, etc. inside the file are not global.
Is there any way that I can make it work, or is this whole exercise pointless?
See below for the code.
function import($a,$b = 1) {
global $options;
if($b == 1) $folder = "internal_functions";
elseif($b == 2) $folder = "external_functions";
else $folder = $b;
$file_path = $options['LIB_DIR']."/".$folder."/".$a.".php";
if(@!file_exists($file_path)) {
$_criticalFiles = array("sessionService/session_loader", "databaseService/db_connection","userService/isLoggedIn");
if(in_array($a,$_criticalFiles)) {
die("<center><h1>Critical Error.<br />Could not find {$a}.</h1></center>");
}
} else {
require_once($file_path);
}
}
Thanks