Is it possible to do something like:
"psr-4": {
"App\\": "src/",
"Tech\\": "src/Tech/"
}
As you see there is App
namespace for src
folder but in src/Tech/
must be another just Tech
namespace. I have tried it but always getting error:
Cannot declare class, because the name is already in use
Yes, it is possible, although I don't know any good reason to do such thing - it just makes harder to understand namespaces structure.
The error Cannot declare class, because the name is already in use
is probably caused by FQN ambiguity, for example if you have file:
<?php
namespace App;
use Tech\MyClass;
$myClass = new MyClass();
And you have App\MyClass
then import for MyClass
is ambiguous - new MyClass()
could either mean new \App\MyClass()
or new \Tech\MyClass()
. You need to use aliases in this case:
<?php
namespace App;
use Tech\MyClass as TechMyClass;
$myClass = new MyClass();
$myTechClass = new TechMyClass();