问题描述
我使用CakePHP,我想知道你们把isset()或!empty()在视图中的所有变量?还是应该依赖于数据验证?
我想你应该知道 isset $>之间的区别。 c $ c>和 empty
并使用满足您需要的那个。
如果变量具有非空和非零值,则
将返回 FALSE
。
以下值被认为是空的
:
-
(一个空字符串)
-
0
0作为整数)
-
0
(0作为字符串)
- code> NULL
FALSE
var $ var;
变量已声明,但类中没有值)另一方面 isset $ c $如果变量不存在或者已经用
unset()
取消设置,则c>将返回 FALSE
已设置为 NULL
。
Hi I'm using CakePHP and I'm wondering do you guys puts isset() or !empty() around all of your variables in the views? Or should I depend on the data validation? What would be the suggested solution?
I think you should know the differences between isset
and empty
and use the one that fulfills your needs.
empty
will return FALSE
if the variable has a non-empty and non-zero value.
The following values are considered to be empty:
""
(an empty string)0
(0 as an integer)"0"
(0 as a string)NULL
FALSE
array()
(an empty array)var $var;
(a variable declared, but without a value in a class)
On the other hand isset
will return FALSE
if the variable does not exist or has been unset with unset()
, or the variable has been set to NULL
.
这篇关于isset()或!empty()函数对视图中的所有变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!