我只是想确保如果将FALSE
作为参数传递给empty()
,它将返回TRUE
:
var_dump(empty(FALSE));
但我不能。这是我得到的:
PHP Parse error: syntax error, unexpected ')', expecting :: (T_PAAMAYIM_NEKUDOTAYIM) in Command line code on line 1
当我在cmd:中运行此代码时
C:'>php -r "echo empty(FALSE);";
我得到了这个结果:
PHP Parse error: syntax error, unexpected ')', expecting :: (T_PAAMAYIM_NEKUDOTAYIM) in Command line code on line
Parse error: syntax error, unexpected ')', expecting :: (T_PAAMAYIM_NEKUDOTAYIM) in Command line code on line 1
我想它会回应1
或0
。但事实并非如此。有什么想法吗?
empty
只允许传递命名变量。
发件人http://php.net/empty
在PHP 5.5之前,empty((只支持变量;任何其他操作都会导致解析错误。换句话说,以下内容将不起作用:空(trim($name((。相反,请使用trim($name(==false。
同样来自同一页面,
如果变量不存在,empty((不会生成警告。
empty
需要一个变量。您需要传递这样一个变量:
$var = false;
if (empty($var))
Changelog
Version Description
5.5.0 empty() now supports expressions, rather than only variables.
http://php.net/manual/en/function.empty.php