- Building RESTful Web Services with PHP 7
- Haafiz Waheed ud din Ahmad
- 147字
- 2021-07-03 00:02:22
Group use declarations
Classes, functions, and constants, which are in the same namespace, can be now imported in a single use statement. Previously, multiple use statements were required for that. Here is an example to understand it better:
<?php
// use statement in Pre-PHP7 code
use abc\namespace\ClassA;
use abc\namespace\ClassB;
use abc\namespace\ClassC as C;
use function abc\namespace\funcA;
use function abc\namespace\funcB;
use function abc\namespace\funcC;
use const abc\namespace\ConstA;
use const abc\namespace\ConstB;
use const abc\namespace\ConstC;
// PHP 7+ code
use abc\namespace\{ClassA, ClassB, ClassC as C};
use function abc\namespace\{funcA, funcB, funcC};
use const abc\namespace\{ConstA, ConstB, ConstC};
As you can see from this example, how convenient the group use statement is, it is clearly visible. Curly braces with comma separated values are used to group values such as {classA, classB, classC as C}, resulting in the grouped use statement, instead of separately using the use statement for all these three classes, three times.
推薦閱讀
- Beginning C++ Game Programming
- Building Modern Web Applications Using Angular
- 編程的修煉
- 小創客玩轉圖形化編程
- Python網絡爬蟲從入門到實踐(第2版)
- Microsoft System Center Orchestrator 2012 R2 Essentials
- R Deep Learning Cookbook
- 動手學數據結構與算法
- Test-Driven Machine Learning
- Learning Docker Networking
- 案例式C語言程序設計實驗指導
- Spring MVC+MyBatis開發從入門到項目實踐(超值版)
- 大話Java:程序設計從入門到精通
- Visual Studio Code 權威指南
- Django Design Patterns and Best Practices