Skip to content

Instantly share code, notes, and snippets.

@rochellelewis
Created November 10, 2015 15:52
Show Gist options
  • Save rochellelewis/55946dfb6f544b52870e to your computer and use it in GitHub Desktop.
Save rochellelewis/55946dfb6f544b52870e to your computer and use it in GitHub Desktop.
Class Autoloader
<?php
/**
* Class Autoloader
* stolen from Skyler
* sin verguenza
*
* @author Skyler Rexroad
*/
spl_autoload_register("Autoloader::classLoader");
class Autoloader {
/**
* This function autoloads classes if they exist
*
* @param string $className name of class to load
* @return bool false if classes can not be loaded
**/
public static function classLoader($className) {
$className = strtolower($className);
if(is_readable(__DIR__ . "/$className.php")) {
require_once(__DIR__ . "/$className.php");
} else {
return(false);
}
}
}
@rochellelewis
Copy link
Author

Add the above file to your /classes directory.

Then at the top of each of your class files:
require_once("autoload.php");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment