Comparison of empty, isset, and is_null (14 ). Empty, isset, and is_null functions have some problems. It even brings some security bugs to your programs. Most of the time, empty considers isset to be similar. Therefore, some problems are encountered when using functions such as empty, isset, and is_null. It even brings some security bugs to your programs. Most of the time, empty considers isset to be similar. Therefore, during development, I did not pay attention to it. when a piece of code is used as a process judgment, a bug occurs.
I. Examples
A. a variable is not defined. how should we judge it?
View source Print?
02 |
# Does not exist $test Variable |
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" ; |
The test result is:
The result is: empty and isset first checks whether the variable exists and then checks the variable value. Is_null only checks the variable value directly and determines whether it is null. Therefore, if the variable is undefined, an error occurs!
1 2 3 4
Http://www.bkjia.com/PHPjc/632335.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/632335.htmlTechArticleempty,isset,is_null when these functions, encountered some problems. It even brings some security bugs to your programs. Most of the time, empty considers isset to be similar. So open...