php7的写法要求更加严谨
直接看代码
<?php
class test {
public static function test1($name, $name1)
{
echo $name . "-" . $name1;
}
}
$testArr = array("test" , "test1");
$test = new test();
$test->$testArr[1]("bill", "test"); // 这行代码有问题
这段代码在php5下面运行的结果是 bill-test.没啥问题
但是在php7下面会报错
在php7下面有几种改进。(本身以上写法就有问题,但是调试起来不容易发现)
应该改为:
$test->{$testArr[1]}("bill", "test");
或者更加规范的写法:
call_user_func_array(array($test, $testArr[1]), array("bill", "test"));