1

I am trying to run some of my code by each time, i am getting this error, i am using the lates version of php. i replaced my caused as per the error; from this

function __autoload($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."); }

to this

function spl_autoload_register($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."); } then got another error message

Fatal error: Cannot redeclare spl_autoload_register() in D:\XAMPP\htdocs\marimar\includes\functions.php on line 37 Any help on how to solve this. here is the complete code: https://www.mediafire.com/file/l1hwccshou9dhjh/functions.php/filet

2
  • Can you share code of that class? Nov 9, 2020 at 4:22
  • Same issue for me..is there any solution ? Feb 12, 2021 at 14:26

1 Answer 1

0

Because you are simply trying to create / redeem a function with the name of an existing native function :

function spl_autoload_register($class){require_once"{$class}.class.php";} If the intention is to use spl_autoload_register , the correct would be to do this:

function meu_autoloader($class) { require_once"{$class}.class.php"; }

spl_autoload_register('meu_autoloader'); Or use closure (PHP anonymous function) directly:

spl_autoload_register(function ($class) { require_once"{$class}.class.php"; });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.