SecondException $e) {
// handle first and second exceptions
} catch (\Exception $e) {
// ...
}
7、list()现在支持键名
现在list()支持在它内部去指定键名。这意味着它可以将任意类型的数组 都赋值给一些变量(与短数组语法类似)
$data = [
['id' => 1, 'name' => 'Tom'],
['id' => 2, 'name' => 'Fred'],
];
while (list('id' => $id, 'name' => $name) = $data) {
// logic here with $id and $name
}8、支持为负的字符串偏移量
现在所有接偏移量的内置的基于字符串的函数都支持接受负数作为偏移量,包括数组解引用操作符([]).
var_dump("abcdef"[-2]);
var_dump(strpos("aabbcc", "b", -3));以上例程会输出:
string (1) "e"
int(3)9、ext/openssl 支持 AEAD
通过给openssl_encrypt()和openssl_decrypt() 添加额外参数,现在支持了AEAD (模式 GCM and CCM)。
通过 Closure::fromCallable() 将callables转为闭包
Closure新增了一个静态方法,用于将callable快速地 转为一个Closure 对象。
class Test {
public function exposeFunction() {
return Closure::fromCallable([$this, 'privateFunction']);
}
private function privateFunction($param) {
var_dump($param);
}
}
$privFunc = (new Test)->exposeFunction();
$privFunc('some value');以上例程会输出:
string(10) "some value"10、异步信号处理 Asynchronous signal handling
A new function called pcntl_async_signals() has been introduced to enable asynchronous signal handling without using ticks (which introduce a lot of overhead).
增加了一个新函数 pcntl_async_signals()来处理异步信号,不需要再使用ticks(它会增加占用资源)
pcntl_async_signals(true); // turn on async signals
pcntl_signal(SIGHUP, function($sig) {
echo "SIGHUP\n";
});
posix_kill(posix_getpid(), SIGHUP);以上例程会输出:
SIGHUP11、HTTP/2 服务器推送支持 ext/curl
Support for server push has been added to the CURL extension (requires version 7.46 and above). This can be leveraged through the curl_multi_setopt() function with the new CURLMOPT_PUSHFUNCTION constant. The constants CURL_PUST_OK and CURL_PUSH_DENY have also been added so that the execution of the server push callback can either be approved or denied.
翻译:
对于服务器推送支持添加到curl扩展(需要7.46及以上版本)。
可以通过用新的CURLMOPT_PUSHFUNCTION常量 让curl_multi_setopt()函数使用。
也增加了常量CURL_PUST_OK和CURL_PUSH_DENY,可以批准或拒绝 服务器推送回调的执行
相关文章推荐:
php7和php5有什么不同之处?php5与php7之间的对比
PHP新特性:finally关键字的用法
以上就是PHP7.0和php7.1中的语法新特性的总结的详细内容,更多请关注php中文网其它相关文章!
网站建设是一个广义的术语,涵盖了许多不同的技能和学科中所使用的生产和维护的网站。
关键词:PHP7.0与php7.1中的语法新特征的总结