PHP how to import all classes from another namespace
You can use the "as" for shortening and aliasing long namespaces
composer.json
{
"autoload": {
"psr-4": {
"Lorem\\Ipsum\\": "lorem/ipsum",
"Lorem\\Ipsum\\Dolor\\": "lorem/ipsum/dolor",
"Lorem\\Ipsum\\Dolor\\Sit\\": "lorem/ipsum/dolor/sit"
}
}
}
index.php
<?php
use Lorem\Ipsum\Dolor\Sit as FOO;
define ('BASE_PATH',dirname(__FILE__));
require BASE_PATH.DIRECTORY_SEPARATOR.'vendor'.DIRECTORY_SEPARATOR.'autoload.php';
$bar = new FOO\Bar();
$baz = new FOO\Baz();
$qux = new FOO\Qux();
This is not possible in PHP.
All you can do is:
namespace Foo;
use Bar;
$obj = new Bar\SomeClassFromBar();