【发布时间】:2011-11-30 22:57:42
【问题描述】:
愚蠢的问题,我知道,但是如果我不知道是否设置了变量$var,我应该使用
isset($var) && !empty($var)
检查它是否有任何值,或者是
!empty($var) 够吗?如果第二种情况$var为null,会不会有问题?
【问题讨论】:
-
为什么不直接查看php手册php.net/manual/en/function.empty.php
-
按照这个标准,StackOverflow 中不会有任何问题,对吧?
-
克里斯特说得有道理。手册指出
empty() is the opposite of (boolean) var, except that no warning is generated when the variable is not set.您可以由此得出结论,不 使用isset()是可以的。不过,我并不反对您的问题,因为其他人可能不会建立这种联系。 -
哦,我不知道它在手册中如此明确。我认为只有在某些情况下使用空就足够了。无论如何,谢谢大家的回答!