Home  >  Article  >  Backend Development  >  A brief analysis of the Group use declarations feature of php7

A brief analysis of the Group use declarations feature of php7

藏色散人
藏色散人forward
2021-12-20 14:08:421710browse

This article is provided by the PHP7 tutorial column to introduce you to the new features of php7, Group use declarations. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

php7 new features Group use declarations

Classes, functions and constants imported from the same namespace can now be imported at once through a single use statement .

I feel that this new feature should be used a lot in daily life, because when PHP7 introduced classes under the same namespace before, it usually used only a few, as shown below:

// PHP 7 之前的代码
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;

Among the new features of php7, batch introduction is supported, which greatly reduces the use of repeated codes:

// PHP 7+ 及更高版本的代码
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 example codes are all from the official PHP manual. They are very simple and do not need to be said. Just read and use them. That's right.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of A brief analysis of the Group use declarations feature of php7. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:juejin.im. If there is any infringement, please contact admin@php.cn delete