I can not load classes using spl_autoload_register

1

I'm trying to load a class that is in another folder in the core.php file and I'm not getting

My browser reports this message

  

Fatal error: Uncaught Error: Class 'Core' not found in   /var/www/html/cursophp/superAdvanced/mvc/views/index.php:18 Stack   trace: # 0 {main} thrown in   /var/www/html/cursophp/superAdvanced/mvc/views/index.php on line 18

Below is the content of the index.php file

    spl_autoload_register(function($class){
    if (strpos($class, 'Controller') > -1) {
        if (file_exists('controllers/'.$class.'.php')){
            require_once 'controllers/'.$class.'.php';

        }else if(file_exits('models/'.$class.'.php')){
            require_once 'models/'.$class.'.php';

        }else {
            require_once 'core/'.$class.'.php';
        }


    }
});
$core = new Core();

Below is the core.php file

<?php

class Core {

}

?>
    
asked by anonymous 18.05.2018 / 14:45

1 answer

0

I discovered the problem in fact, the file name was core.php while the class name was Core () ie the file name was different from the class name, from the time I put the two as the same name require_once calling the file started to work, if someone can clarify the answer a little more I thank

    
19.05.2018 / 01:34