Skip to content

Instantly share code, notes, and snippets.

@BernardoSilva
Created March 2, 2014 19:21
Show Gist options
  • Save BernardoSilva/9312170 to your computer and use it in GitHub Desktop.
Save BernardoSilva/9312170 to your computer and use it in GitHub Desktop.
example os a standard php autoloader following the PSR-0
<?php
function autoload($className)
{
$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