Skip to content

Instantly share code, notes, and snippets.

@dave1010
Created May 25, 2011 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dave1010/990910 to your computer and use it in GitHub Desktop.
Save dave1010/990910 to your computer and use it in GitHub Desktop.
PHP 5.3 autoloader
<?php
// PHP Standards Working Group PSR-0
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