dimanche 24 septembre 2017

My autoload function doesnt work but it seems the class is loaded PHP

I'm a new PHP deveploper and I'm having a bad time with the autoload function. This is the error.

public class dog{ public function hey($var){ echo $var; } }
Fatal error: Uncaught Error: Class 'dog' not found in C:\xampp\htdocs\ebay\index.php:3 Stack trace: #0 {main} thrown in C:\xampp\htdocs\ebay\index.php on line 3

It shows the class but then echo a error

This is the autoload function.
r

equire_once("config.php");
     spl_autoload_register("my_auto_load");
    function my_auto_load($class_name){

        $path = "classes";

        require_once($path.DS.$class_name.".php");
    }

And this is the index file

require_once("config.php");
 spl_autoload_register("my_auto_load");
function my_auto_load($class_name){

    $path = "classes";

    require_once($path.DS.$class_name.".php");
}

And this is the index file

?php 
require_once("inc/autoload.php");
$dog= new dog();
$dog->hey("KLK");
?>




Aucun commentaire:

Enregistrer un commentaire