- 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.
推薦閱讀
- ASP.NET MVC4框架揭秘
- 云計算通俗講義(第3版)
- The HTML and CSS Workshop
- Mastering Linux Network Administration
- Test-Driven Machine Learning
- Mastering Git
- QGIS Python Programming Cookbook(Second Edition)
- Android應用開發深入學習實錄
- SwiftUI極簡開發
- Java Hibernate Cookbook
- SQL Server 2012 數據庫應用教程(第3版)
- 一覽眾山?。篈SP.NET Web開發修行實錄
- 深度學習的數學:使用Python語言
- Salt Cookbook
- Visual FoxPro程序設計