- PHP 7 教程
- PHP 7 - 主页
- PHP 7 - 简介
- PHP 7 - 性能
- PHP 7 - 环境设置
- PHP 7 - 标量类型声明
- PHP 7 - 返回类型声明
- PHP 7 - 空合并运算符
- PHP 7 - 宇宙飞船操作员
- PHP 7 - 常量数组
- PHP 7 - 匿名类
- PHP 7 - 闭包::call()
- PHP 7 - 过滤反序列化()
- PHP 7 - 国际字符
- PHP 7 - CSPRNG
- PHP 7 - 期望
- PHP 7 - use 语句
- PHP 7 - 错误处理
- PHP 7 - 整数除法
- PHP 7 - 会话选项
- PHP 7 - 已弃用的功能
- PHP 7 - 删除的扩展和 SAPI
- PHP 7 有用资源
- PHP 7 - 快速指南
- PHP 7 - 有用的资源
- PHP 7 - 讨论
PHP 7 - use 语句
从 PHP7 开始,单个 use 语句可用于从同一命名空间导入类、函数和常量,而不是多个 use 语句。
例子
<?php
// Before PHP 7
use com\tutorialspoint\ClassA;
use com\tutorialspoint\ClassB;
use com\tutorialspoint\ClassC as C;
use function com\tutorialspoint\fn_a;
use function com\tutorialspoint\fn_b;
use function com\tutorialspoint\fn_c;
use const com\tutorialspoint\ConstA;
use const com\tutorialspoint\ConstB;
use const com\tutorialspoint\ConstC;
// PHP 7+ code
use com\tutorialspoint\{ClassA, ClassB, ClassC as C};
use function com\tutorialspoint\{fn_a, fn_b, fn_c};
use const com\tutorialspoint\{ConstA, ConstB, ConstC};
?>