I'm trying to find a way to mass apply these namespaces, as this would be inconvenient to write out. I know I can simply do, use jream\ as j
but I would like to see if it's possible to avoid the backslash.
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');
Isn't there a way to say something along these lines: jream\\* as *;
?
Any tips would be appreciated :)
At the very least you can skip all the redundant as
aliasing:
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 out one by one, then indeed the only real choice is to alias the namespace as a whole and use a backslash:
use jream as j;
new j\Autoload;
Isn't there a way to say something along these lines: 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 wouldn't really recommend doing it.
And of course, if you want to just change the default namespace:
namespace jream;
new Autoload('../jream');
That is all an import jream.*
could ever mean in PHP, since PHP has absolutely no way to determine if a class could possibly exist in a certain namespace unless you inform it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With