Is there a shortcut for the PHP namespace for this?

I am trying to find a way to mass-use these namespaces, as that would be inconvenient to write down. I know that I can just do it, use jream\ as j , but I would like to see if backslash can be avoided.

 require '../jream/Autoload.php'; use jream\Autoload as Autoload, jream\Database as Database, jream\Exception as Exception, jream\Form as Form, jream\Hash as Hash, jream\Output as Output, jream\Registry as Registry, jream\Session as Session; new Autoload('../jream'); 

Is there no way to say something in these lines: jream\\* as *; ?

Any advice would be appreciated :)

+7
source share
2 answers

At the very least, you can skip all redundant anti-aliasing as :

 use jream\Autoload, jream\Database, jream\Exception, jream\Form, jream\Hash, jream\Output, jream\Registry, jream\Session; 

If you want to use everything in the namespace without typing it one by one, then the really only real choice is the alias of the namespace as a whole and the use of a backslash:

 use jream as j; new j\Autoload; 
+6
source

Is there no way to say something like that: jream \ * as *;

No, but you can do this:

 // use-jream.php class Autoload extends jream\Autoload {} class Database extends jream\Database {} ... // index.php require_once 'use-jream.php' new Autoload('../jream'); 

But I would not recommend doing this.

And of course, if you just want to change the default namespace:

 namespace jream; new Autoload('../jream'); 

This is all that import jream.* Can ever mean in PHP, as PHP has absolutely no way to determine if a class can exist in a particular namespace if you don't tell about it.

+3
source

All Articles