this my code i have is someone call tell me what is going wrong

40 Views Asked by At

please may someone help to fix this problem,I tried to use spl_autoload_register to replace auto load function

here is the error

function spl_autoload_register( function($class_name) {
    $class_name = strtolower($class_name);
    $path = LIB_PATH.DS."{$class_name}.php";
    if(file_exists($path)){
        require_once($path);
    }else{
        die("The file {$class_name}.php could not be found.");
    }
                
})
1

There are 1 best solutions below

0
I try so hard but I cry harder On

The error is due to putting function in front of the spl_autoload_register. It should be as follow:

spl_autoload_register(function ($class_name) {
    include $class_name . '.php';
});

Remember, you are not creating the spl_autoload_register function, you're calling it. calling is as follow: functionToCall(); You then pass an anonymous function to your spl_autoload_register as an argument.