Last active
May 6, 2025 11:21
-
-
Save mkgeeky/f389e720128013c74f1e9285289ea13b to your computer and use it in GitHub Desktop.
Own autoloader with multiple directorys
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Autoloader | |
{ | |
public static function register() | |
{ | |
spl_autoload_register(function ($class) { | |
$ff = str_replace('\\', DIRECTORY_SEPARATOR, $class); | |
$Class_Dirs = array ( | |
"/Class/", | |
"/Controllers/", | |
"/Controllers/Content/", | |
); | |
for ($i = 0; $i < count($Class_Dirs); $i++) | |
{ | |
$file = $_SERVER["DOCUMENT_ROOT"].$Class_Dirs[$i].$ff.'.php'; | |
if (file_exists($file)) | |
{ | |
require $file; | |
return true; | |
} | |
} | |
return false; | |
}); | |
} | |
} | |
Autoloader::register(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment