Autoloader for PHP
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 | |
/** | |
* A very simple autoloader | |
*/ | |
class Autoloader | |
{ | |
/** | |
* Only use this class statically. | |
* @ignore | |
*/ | |
private function __construct() | |
{ } | |
/** | |
* Registers Autoloader as an SPL autoloader. | |
*/ | |
public static function register() | |
{ | |
spl_autoload_register(array(__CLASS__, 'autoload')); | |
} | |
/** | |
* Handles autoloading of classes. | |
* | |
* @param string $class A class name. | |
*/ | |
public static function autoload($class) | |
{ | |
$file = strtr($class, '\\_', '//') . '.php'; | |
if (@fopen($file, 'r', true)) require_once $file; | |
} | |
} | |
Autoloader::register(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment