- 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.
推薦閱讀
- Node.js+Webpack開(kāi)發(fā)實(shí)戰(zhàn)
- Visual C++串口通信開(kāi)發(fā)入門(mén)與編程實(shí)踐
- 企業(yè)級(jí)Java EE架構(gòu)設(shè)計(jì)精深實(shí)踐
- JavaScript 網(wǎng)頁(yè)編程從入門(mén)到精通 (清華社"視頻大講堂"大系·網(wǎng)絡(luò)開(kāi)發(fā)視頻大講堂)
- Access 2010數(shù)據(jù)庫(kù)基礎(chǔ)與應(yīng)用項(xiàng)目式教程(第3版)
- Python神經(jīng)網(wǎng)絡(luò)項(xiàng)目實(shí)戰(zhàn)
- SSM輕量級(jí)框架應(yīng)用實(shí)戰(zhàn)
- 精通網(wǎng)絡(luò)視頻核心開(kāi)發(fā)技術(shù)
- Linux Device Drivers Development
- Flutter跨平臺(tái)開(kāi)發(fā)入門(mén)與實(shí)戰(zhàn)
- Learning PHP 7
- ServiceNow:Building Powerful Workflows
- Scratch3.0趣味編程動(dòng)手玩:比賽訓(xùn)練營(yíng)
- Scala for Machine Learning(Second Edition)
- Unity 3D腳本編程:使用C#語(yǔ)言開(kāi)發(fā)跨平臺(tái)游戲