Home > Backend Development > PHP7 > body text

A brief analysis of the Group use declarations feature of php7

藏色散人
Release: 2023-02-18 09:40:01
forward
1711 people have browsed it

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;
Copy after login

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};
Copy after login

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!

Related labels:
source:juejin.im
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template