使用empty检查一个函数返回的结果时会报错:
Fatal error: Can't use function return value in write context
例如:
<?php
echo empty(strlen('be-evil.org'));
?>
到PHP手册里面查看,在empty函数描述的地方有以下文字:
Note: empty() only checks variables as anything else will result in a parse error. In other words, the following will not work: empty(trim($name)).
empty()
只检测变量,检测任何非变量的东西都将导致解析错误!
因此,不能拿empty来直接检测函数返回的值,解决办法是:
<?php
$length = strlen('be-evil.org');
echo empty($length);
?>