spl_autoload_register(function (string $class_name): void {
$conf = Config::get();
$classDir = $conf['INCLUDE_DIR'] . '/classes/';
// Convert underscore-namespaced class names to directory paths
// e.g. "User_Member" → "classes/User/Member.php"
$classFile = str_replace('_', '/', $class_name);
$fullPath = $classDir . $classFile . '.php';
if (file_exists($fullPath)) {
require_once $fullPath;
return;
}
// Fall back to legacy include files only when the class lives in one of them.
// Map known class names to the inc file that defines them so we don't
// blindly load every inc on every miss.
$incDir = $conf['INCLUDE_DIR'];
$incMap = [
'Page' => "$incDir/page.inc.php",
'Image' => "$incDir/image.inc.php",
'Member' => "$incDir/user.inc.php", // ← fixes your immediate error
'User' => "$incDir/user.inc.php",
'Sport' => "$incDir/sport.inc.php",
'PM' => "$incDir/pm.inc.php",
'Event' => "$incDir/event.inc.php",
'Location' => "$incDir/location.inc.php",
'Comment' => "$incDir/comment.inc.php",
];
if (isset($incMap[$class_name])) {
require_once $incMap[$class_name];
return;
}
// PHPMailer (legacy class names)
$mailerMap = [
'PHPMailer' => "$incDir/phpmailer/class.phpmailer.php",
'SMTP' => "$incDir/phpmailer/class.smtp.php",
];
if (isset($mailerMap[$class_name])) {
require_once $mailerMap[$class_name];
return;
}
// Nothing found — let PHP raise its own "class not found" error,
// or throw explicitly if you prefer the RuntimeException style.
throw new \RuntimeException(
"Class '$class_name' could not be loaded. "
. "Checked $fullPath and legacy inc files. "
. "INCLUDE_DIR={$conf['INCLUDE_DIR']}"
);
});
Fatal error: Class 'Page_Location' not found in /var/www/hosts/sportkin/public_html/location/index.php on line 5