Skip to content

Instantly share code, notes, and snippets.

@Wolfy64
Created October 9, 2018 14:38
Show Gist options
  • Save Wolfy64/0e44568f4f0d0d0e74083cdf7385017d to your computer and use it in GitHub Desktop.
Save Wolfy64/0e44568f4f0d0d0e74083cdf7385017d to your computer and use it in GitHub Desktop.
PHP Autoloader
<?php
namespace App\Classes;
/**
* Autoloader for class and namespace
*/
Class Autoloader
{
/**
* To load class and it's path via the function autoload
* @return void
*/
static function register()
{
spl_autoload_register(array(__CLASS__, 'autoload'));
}
/**
* Require path and namespace of the class
* @param $class
* @return void
*/
static function autoload($class)
{
$class = str_replace(__NAMESPACE__.'\\', '', $class);
require '../Classes/'. $class.'.php';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment