Home  >  Article  >  Backend Development  >  isset()和empty()的有关问题

isset()和empty()的有关问题

WBOY
WBOYOriginal
2016-06-13 12:25:59760browse

isset()和empty()的问题?
我看公司的代码很多都是if(isset($var) && !empty($var)),可真的有写成这样的必要吗?
我上网百度,百度也有人说当要判断一个变量存在且不为空时,先isset 函数,再用empty 函数。
可是我看php.net的empty()函数介绍里面说了,当var存在,并且是一个非空非零的值时返回FALSE,否则返回 TRUE。
那么if(!empty($var))和if(isset($var) && !empty($var))的作用应该是一样的,没有区别,并没有写成后面样子的需要吧?请大神解答。
------解决思路----------------------
if(isset($var) && !empty($var))
的意思是:
当 $var 已定义,且 $var 不为空 时,进入 true 分支

这和 if(!empty($var)) 的效果是一致的!

写成那样应该是为了便于调试程序,或是说在程序交付使用时没有删去调试的桩

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn