- 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.
推薦閱讀
- Advanced Quantitative Finance with C++
- Fundamentals of Linux
- LabVIEW Graphical Programming Cookbook
- Visual Basic 6.0程序設計計算機組裝與維修
- 深入淺出WPF
- 數據結構習題精解(C語言實現+微課視頻)
- INSTANT Django 1.5 Application Development Starter
- 軟件測試教程
- R用戶Python學習指南:數據科學方法
- Django實戰:Python Web典型模塊與項目開發
- 零基礎學C語言程序設計
- RESTful Web Clients:基于超媒體的可復用客戶端
- IBM RUP參考與認證指南
- 透視C#核心技術:系統架構及移動端開發
- 跟小樓老師學用Axure RP 9:玩轉產品原型設計