PSR-0 自动加载器约定是否需要使用映射到目录结构的命名空间?
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;
}
最佳答案
PSR-0 需要它。
Each namespace separator is converted to a DIRECTORY_SEPARATOR when loading from the file system.
和
The fully-qualified namespace and class is suffixed with .php when loading from the file system.
https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md
关于php - PSR-0 自动加载器 : Namespaces and the directory structure,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17420703/