Autoloader code:
<?php
spl_autoload_register('myAutoLoader');
function myAutoLoader($className){
$path = "/classes/";
$extension = ".class.php";
$fullPath = $path . $className . $extension;
echo $fullPath;
if(file_exists($fullpath)){
require $fullPath;
}
}
?>
And it is throwing error, that class is not found for some reason. I even tried to print out the fullpath variable, and it matches the path, in which class is located. File structure: https://prnt.sc/17v3qsk Fullpath value: "/classes/DatabaseConnect.class.php"
Sample index.php code that I am trying to use it in:
<?php
include 'includes/autoloader.inc.php';
$dbConnect = new DatabaseConnect('127.0.0.1','root','','test');
if($dbConnect->connect_errno){
die("Failed to connect to the database: " . $dbConnect->connect_error);
}
echo 'connected successfully';
?>
EDIT 1:
<?php
spl_autoload_register('myAutoLoader');
function myAutoLoader($className){
$path = "/classes/"; // <-- Notice the ".."
$extension = ".class.php";
$fullPath = $_SERVER["DOCUMENT_ROOT"] . $path . $className . $extension;
echo $fullPath;
if(file_exists($fullpath)){
require $fullPath;
}
}
?>