'Use multiple classes in other namespaces
If I have some php classes inside a namespace com\test
and want to import all of them into another php file how can do that?
use com\test\ClassA
use com\test\ClassB
...
use com\test\* give me syntax error.
Solution 1:[1]
From PHP 7.0 onwards, classes, functions, and constants being imported from the same namespace can be grouped together in a single
usestatement.
Like this way:
use com\test\{ClassA, ClassB};
$a = new ClassA;
$b = new ClassB;
Read more here: PHP Manual for Aliasing/Importing
Solution 2:[2]
I think you can't do such thing.
You can do:
use com\test
and refer to your classes at later time as:
test\ClassA
test\ClassB
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | abrahamcalf |
| Solution 2 | Kamil Szot |
