PHP头条
热点:

php Note: empty() only checks variables as anything错误


今天在利用empty()函数判断一个变量是否为null是发现提示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检查一个函数返回的结果时会报如下的一个致命错误:

Fatal error: Can't use function return value in write context in : ..................

例如:

echo empty(yourfunction(xx, oo));

到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来直接检测函数返回的值,需要先把函数的返回值赋给某个变量,然后去用empty检测这个变量。

所以,我们可以写成如下的形式:

$return= yourfunction(xx, oo);

echo empty(return);

www.phpzy.comtrue/php/35792.htmlTechArticlephp Note: empty() only checks variables as anything错误 今天在利用empty()函数判断一个变量是否为null是发现提示Note: empty() only checks variables as anything else will result in a parse error. In other words, the follo...

相关文章

PHP之友评论

今天推荐