Created
October 9, 2018 14:38
-
-
Save Wolfy64/0e44568f4f0d0d0e74083cdf7385017d to your computer and use it in GitHub Desktop.
PHP Autoloader
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 | |
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