empty,isset,is_null比较(1/4)_PHP教程
时间:2021-07-01 10:21:17
帮助过:8人阅读
empty,isset,is_null 这几个函数时候,遇到一些问题。甚至给自己的程序带来一些安全隐患的bug。很多时候,对于isset,empty都认为差不多。因此开发时候,就没有注意,一段作为流程判断时候,就出现bug问题了。
一、举例说明
a.一个变量没有定义,我们该怎么样去判断呢?
view source
print?
04 |
$isset = isset( $test )? "test is define!" : "test is undefine!" ; |
05 |
echo "isset:$issetrn" ; |
07 |
$empty =! empty ( $test )? "test is define!" : "test is undefine!" ; |
08 |
echo "empty:$emptyrn" ; |
10 |
$is_null = is_null ( $test )? "test is define!" : "test is undefine!" ; |
11 |
echo "is_null:$is_nullrn" ; |
测试结果是:
![image image](http://www.bkjia.com/uploads/allimg/131231/1F4364541-0.png)
结果出来了:empty,isset首先都会检查变量是否存在,然后对变量值进行检测。而is_null 只是直接检查变量值,是否为null,因此如果变量未定义就会出现错误!
1 2 3 4
http://www.bkjia.com/PHPjc/632335.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/632335.htmlTechArticleempty,isset,is_null 这几个函数时候,遇到一些问题。甚至给自己的程序带来一些安全隐患的bug。很多时候,对于isset,empty都认为差不多。因此开...