php7的新特性

php7新特性

太空船操作符 <=>

echo 1<=>1; //0

echo 1<=>2: //-1

echo 2<=>1;//1

类型声明:

declare (strict_types=1) // strict_types=1表示开启严格模式

function sum(int...$ints):int{

return array_sum($ints);

}

3.null合并操作符

$page:0;

page??0;

4.常量数组

define("ANIMALS",["doc",'cat','bird'])

5.NameSpace批量导入

use Space{ClassA,ClassB,ClassC}

6.新的try cache 捕获Error未定义的方法,防止异常终止程序

try{

}cache(Error $e){var_dump($e)}

7.闭包的 Closure::call()方法

Class Test(){ private $num = 1}

$f=function(){ return $this->num +1;}

echo $f->call(new Test) //2

8.intdiv函数

intdiv(10,3); 10/3

9.list的方括号写法

$arr = [1,2,3];

list(b,arr;

$arr = [1,2,3];

[b,$arr;

10.抽象语法树 AST

($a)['b'] = 1;

 

回顾总结:

下载http://php.net/releases/

./configure

make && make install

基准测试:http://php.net/releases/

php Zend/bench.php

php Zend/micro_bench.php

 

原文地址:https://www.cnblogs.com/iifeng/p/11881334.html