Skip to content

Instantly share code, notes, and snippets.

@jasny
Created October 19, 2012 14:38
Show Gist options
  • Save jasny/3918541 to your computer and use it in GitHub Desktop.
Save jasny/3918541 to your computer and use it in GitHub Desktop.
Autoloader for PHP
<?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