Hello,
I have an issue with my autoload not working correctly. I may be missing something, but for the life of me I do not know what. My errorlog states: PHP Fatal error: Uncaught Error: Class ‘user\\full_name’ not found in /my/file/path/to/index.php.
In index.php I am calling my class with namespace as:
$test = new file\class_name();
My autoload function/method is as so:
spl_autoload_register('Autoloader::ClassLoader');
class Autoloader
{
public static function ClassLoader($class)
{
$classFile = str_replace('\\', DIRECTORY_SEPARATOR, $class);
$file_path = __ROOT__ . '/include/class/' . $classFile . '.php';
if (is_file($file_path) && file_exists($file_path))
{
include_once $file_path;
echo $file_path; // Testing that I get an output in index.php.
// and I do.
}
}
}
Any direction on what is incorrect would be greatly appreciated. I have been looking around on the internet to get this far, but cannot find a solution to why this does not work for me. $file_path echos out correctly for the file path, but in my error message I do not know why my Class has \\ when I have str_replace to replace \ . If I str_replace \\\\ to replace the double \ from the namespace I still get the same error, but the echo in the function does not return in index.php.
Thank you,
Leavii