require_once __DIR__.'/lib/Symfony/Component/ClassLoader/UniversalClassLoader.php';
use Symfony\Component\ClassLoader\UniversalClassLoader;
$loader = new UniversalClassLoader();
$loader->registerNamespace('Test', __DIR__ . '/lib');
$loader->register();
$router = new Test\Router;
但是,如果我不想在初始化类时添加命名空间 Test,这可能吗?
喜欢: $router = 新路由器;
...
<?php
namespace Test;
class Router
{
public function __construct() {
echo __CLASS__;
}
}