Skip to content

Instantly share code, notes, and snippets.

@troelsselch
Created November 16, 2016 22:16
Show Gist options
  • Save troelsselch/920d291934d8e3aa4a1b4133237071c4 to your computer and use it in GitHub Desktop.
Save troelsselch/920d291934d8e3aa4a1b4133237071c4 to your computer and use it in GitHub Desktop.
PHP Custom Autoloader
<?php
spl_autoload_register(function($classname) {
$prefix = 'Laundrette\\';
$length = strlen($prefix);
if (substr($classname, 0, $length) == $prefix) {
$filename = 'src/' . substr($classname, $length) . '.php';
$filename = str_replace('\\', '/', $filename);
if (file_exists($filename)) {
require_once($filename);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment