Skip to content

Instantly share code, notes, and snippets.

@will83
Last active November 2, 2017 22:48
Show Gist options
  • Save will83/ffd042372ba28971da2aa04a0ddc9aef to your computer and use it in GitHub Desktop.
Save will83/ffd042372ba28971da2aa04a0ddc9aef to your computer and use it in GitHub Desktop.
Autoloader OOP
<?php
namespace Namespace;
class Autoloader{
static function register(){
spl_autoload_register(array(__CLASS__, 'autoload'));
}
static function autoload($class){
if(strpos($class, __NAMESPACE__ . '\\') === 0){
$class = str_replace(__NAMESPACE__ .'\\', '', $class);
$class = str_replace('\\', '/', $class);
require 'class/' . $class . '.php';
}
}
}
<?php
require 'class/Autoloader.php';
\Namespace\Autoloader::register();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment