PHP语法糖
1.逗号优于点号
$foot = 'hello';
$bar = 'world';
echo $foot . $bar;
echo $foot , $bar;2.$i=$i+1比较低效
$i = 0;
$i++;
$i += 1;
$i = $i + 1;3.用isset代替strlen
$subject = 'hello world';
if (strlen($subject) < 20) {
echo 'strlen too short!' . PHP_EOL;
}
if (!isset($subject[20])) {
echo 'isset too short!' . PHP_EOL;
}4.用strtr代替str_replace
5.PHP用yield实现协程
6.用 “[]” 定义数组
7.用 ** 进行幂运算
8.用 ... 定义变长参数函数
8.函数赋值默认参数:+ 运算符
9.函数赋值默认参数:+ 运算符
10.?? 运算符
11.<=> 比较运算符("太空船"运算符)
12.一句话木马
Last updated