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, 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