Last active
November 2, 2017 22:48
-
-
Save will83/ffd042372ba28971da2aa04a0ddc9aef to your computer and use it in GitHub Desktop.
Autoloader OOP
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 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'; | |
} | |
} | |
} |
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 | |
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