PHP 7在性能方面的突破成为近来最热门的话题之一,目前官方PHP 7.0.0 Beta 2已经发布
新特性
$username = $_GET['user'] ?? 'nobody';
// equivalent to: $username = isset($_GET['user']) ? $_GET['user'] : 'nobody';
$a = 1;
$b = 2;
switch ($a <=> $b)
{
case 1:
echo "a > b";
break;
case 0:
echo "a == b";
break;
case -1:
echo "a < b";
break;
}
function foo(): array {
return [];
}
//标量声明的主要作用是自动实现参数的强制类型转换
//变量类型声明(int, float, string , bool)
function add(int $a, int $b): int {
return $a + $b;
}
class Foo {}
$child = new class extends Foo {};
var_dump($child instanceof Foo); // true
$count = $argv[1];
$a = array();
for ($i = 0; $i < $count; $i++) {
$a[$i] = $i;
}
foreach ($a as $i) {
array_key_exists($i, $a);
}