Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the Group use declarations feature of php7

Shulou Source: shulou.com Published: 2022-06-02 05:58:12 09月28日 Update

This article mainly explains "what are the Group use declarations features of php7". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the Group use declarations features of php7".

Group use declarations of new features of php7

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

I think this new feature should be used a lot, because in the past, when php7 introduced classes under the same namespace, there were only several use, as shown below:

/ / the code before PHP 7, use some\ namespace\ ClassA;use some\ namespace\ ClassB;use some\ namespace\ ClassC as Cash 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 support has been introduced, which greatly reduces the use of duplicate code:

/ / PHP 7 + and later code 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 sample code is from the php official manual, very simple, do not need to say more, look and use it.

Thank you for your reading, the above is the content of "what is the Group use declarations feature of php7". After the study of this article, I believe you have a deeper understanding of what the Group use declarations feature of php7 is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Features code learning content yes one-time function single can be passed officially that is constants ideas situations feelings manuals articles more versions knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Redmi Apple vpn NVidia