Page 1 of 1

Global namespace alias declaration

Posted: Tue Aug 23, 2011 11:33 am
by jraede
I'm starting to get into the new namespace stuff in 5.3; it's making organizing my MVC stuff a lot easier. One issue I'm having is keeping a namespace alias declaration across different classes. For instance, on my index page, I have

Code: Select all

use \application\auth as Auth;
...and then within a class in, say, the "system" namespace, at /application/system, I want to instantiate an object in the auth namespace. Ideally I'd like to be able to say something like:

Code: Select all

$this->Authorizer = new Auth\AuthAdmin;
...but if I do that then it searches for the relative path /Auth/AuthAdmin.php within the /application/system/ folder. I.E., it tries to include /application/system/Auth/AuthAdmin.php, but obviously can't find it.

This problem likely has to do with how my __autoload function is set up:

Code: Select all

function __autoload($class) {
	$filename = str_replace('\\', '/', $class) . '.php';
	require_once ($filename);
}
But here I'm just making use of the aliases I declared above to easily include the necessary class files. Like I said, this works fine outside of a class scope, but inside of a class with a declared namespace at the top, the aliases are either not being used, or they're being used within the class' namespace.

Odds are I just don't entirely understand how this whole system works, but if someone could point me in the right direction I'd appreciate it.

Thanks!