Skip to content

Instantly share code, notes, and snippets.

@ruliarmando
Created May 15, 2013 09:57
Show Gist options
  • Save ruliarmando/5582892 to your computer and use it in GitHub Desktop.
Save ruliarmando/5582892 to your computer and use it in GitHub Desktop.
<?php
function autoload($className)
{
$className = ltrim($className, '\\');
$fileName = '';
$namespace = '';
if ($lastNsPos = strripos($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