致命错误:无法使用函数返回值
问题描述:
当我使用下面的代码,然后生成致命错误。致命错误:无法使用函数返回值
echo empty(is_resource(true));
错误:
Fatal error: Can't use function return value in write context.
为什么?
答
empty
需要一个变量,如果parameter were passed by reference:
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))
.
所以,你可以这样做:
$var = is_resource(true);
echo empty($var);
但作为is_resource
已经返回一个布尔值,你其实并不需要另一个测试功能。