Created
July 7, 2017 11:04
-
-
Save Firestorm-Graphics/479f75d6b52ee622bac51c80321f8448 to your computer and use it in GitHub Desktop.
Here’s an autoloader class I came up with for one of my framework-free PHP projects. Autoloading is a way to let PHP know how you’ve architected your class file locations hierarchy by supplying it with a function to run. This function will handle the including of the class file. This is awesome because we don’t need to hard code every file inclu…
This file contains 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 { | |
static public function loader($className) { | |
$filename = "Classes/" . str_replace("\\", '/', $className) . ".php"; | |
if (file_exists($filename)) { | |
include($filename); | |
if (class_exists($className)) { | |
return TRUE; | |
} | |
} | |
return FALSE; | |
} | |
} | |
spl_autoload_register('Autoloader::loader'); | |
?> |
This file contains 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
require_once("Classes/Autoloader.php"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment