php 注册自动加载 自己写框架的开端
<?php
// autoloader.php
function autoload_class($className) {
$fileName = '';
$namespace = '';
// Sets the include path as the "src" directory
$includePath = ROOT_PATH.DIRECTORY_SEPARATOR;
if (false !== ($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';
//不切割下划线
$fileName .= $className . '.php';
$fullFileName = $includePath . DIRECTORY_SEPARATOR . $fileName;
if (file_exists($fullFileName)) {
require $fullFileName;
} else {
echo 'Class "'.$className.'" does not exist.';
}
}
spl_autoload_register('autoload_class'); // Registers the autoloader
?>