Home  >  Article  >  Backend Development  >  What is the usage of php7 use

What is the usage of php7 use

藏色散人
藏色散人Original
2020-07-23 09:32:213963browse

php use means that you can use a use in PHP to import classes, functions and constants from the same namespace. The usage statement is "use some\namespace\ClassA; use some\namespace\ClassB;".

What is the usage of php7 use

PHP 7 use statement

PHP 7 can be used A use imports classes, functions and constants from the same namespace:

Example

// PHP 7 之前版本需要使用多次 use
use some\namespace\ClassA;
use some\namespace\ClassB;
use some\namespace\ClassC as C;
use function some\namespace\fn_a;
use function some\namespace\fn_b;
use function some\namespace\fn_c;
use const some\namespace\ConstA;
use const some\namespace\ConstB;
use const some\namespace\ConstC;
// PHP 7+ 之后版本可以使用一个 use 导入同一个 namespace 的类
use some\namespace\{ClassA, ClassB, ClassC as C};
use function some\namespace\{fn_a, fn_b, fn_c};
use const some\namespace\{ConstA, ConstB, ConstC};
?>

The above is the detailed content of What is the usage of php7 use. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn