Skip to content

Instantly share code, notes, and snippets.

@philsturgeon
Created April 19, 2013 00:18
Show Gist options
  • Select an option

  • Save philsturgeon/5417208 to your computer and use it in GitHub Desktop.

Select an option

Save philsturgeon/5417208 to your computer and use it in GitHub Desktop.
Magical PSR-0 Replacement
function autoload($className)
{
if (file_exists('autoload.php')) {
require_once('autoload.php');
return;
}
$className = ltrim($className, '\\');
$fileName = '';
$namespace = '';
if ($lastNsPos = strrpos($className, '\\')) {
$namespace = substr($className, 0, $lastNsPos);
$className = substr($className, $lastNsPos + 1);
$fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
}
$fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
require $fileName;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment