Jimmyt1988
Jimmyt1988

Reputation: 21136

PHP use namespace - A solution to including all classes under a namespace

Is there a solution to having to include all classes individually under a namespace?

My Laravel files are getting huge because I have to keep including a heck load of namespaces... It's pretty awful!

As a temporary solution, why might the following not be working:

namespace.Blah.txt:

use Blah\Blah; 
use Blah\Bloh;

php code:

eval( file_get_contents( "namespace.Blah.txt" );

If I could get this to work, I could evaluate the contents of a file... I do understand it's a bit noob... but... dammit!

Upvotes: 5

Views: 1137

Answers (1)

Antonio Carlos Ribeiro
Antonio Carlos Ribeiro

Reputation: 87719

There isn't, but in PHP 7 you'll be able to

use FooLibrary\Bar\Baz\{ ClassA, ClassB, ClassC, ClassD as Fizbo };

As the following RFC has passed:

https://wiki.php.net/rfc/group_use_declarations

EDIT:

Note that too many uses in a class may be a sign of "smell". Isn't that particular class doing too much? Shouldn't you be creating new "base" classes and extending them?

Upvotes: 7

Related Questions