php项目踩到的empty函数的一个坑

报错信息:

PHP Fatal error:  Can't use function return value in write context in /目录省略.../XXService.php on line 64

代码:

if (empty(trim($anchorUrls))) {
      //......
}

在我笔记本环境上运行上面的代码不会报错,到公司的服务器就报错了,原因是php的版本不同,公司的php版本是5.4,我的php版本是7.1,php5.5之前的版本中,empty()函数的参数只能接收一个变量,检测任何非变量的东西都将导致解析错误。上面我的代码给empty()传了一个字符串,导致报错。

解决:

$anchorUrls = trim($anchorUrls);
   if (empty($anchorUrls)) {
    //......
}

猜你喜欢

转载自www.cnblogs.com/jun1019/p/10176513.html