首页 > php开发 > php Note: empty() only checks variables as anything错误

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 emptyempty(return);

               
               

文章链接:http://www.phprm.com/develop/fs5872.html

随便收藏,请保留本文地址!

标签:variables anything错误

发表留言