Question

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;

But what If I don't want to add the namespace Test when I initialize my classes, is that possible?

Like: $router = new Router;

...

<?php
namespace Test;

class Router
{
    public function __construct() {
        echo __CLASS__;
    }
}
Was it helpful?

Solution

Add another use statement like you see at the top:

use Test\Router;

Now you can:

$router = new Router();

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top