Let's take a look at the functional descriptions of the three functions.
Isset determines whether a variable already exists. if the variable exists, TRUE is returned; otherwise, FALSE is returned.
Empty determines whether the variable is null. if the variable is not null or a non-zero value, empty () returns FALSE. In other words, "", 0, "0", NULL, FALSE, array (), var $ var; and objects without any attributes will be considered empty, if the variable is null, TRUE is returned.
Is_null determines whether the variable is NULL
This is the general explanation, but it is confusing. let's take a look at the specific examples!
From this, we can find that if the variable is "" or 0, or false or null, empty returns true as long as these values are empty.
Isset only determines whether a variable exists. as long as the variable is not null or not assigned a value, the returned result is true. If you use isset () to test a variable that is set to NULL, FALSE is returned. Note that a NULL byte ("\ 0") is not equivalent to the NULL constant of PHP.
Is_null is exactly the opposite result of isset. we can regard it! Isset is an inverse operation of isset.
From the above examples, we can draw the following conclusions (which will be frequently used in programming in the future ):
Assume that $ var is of any type.
When empty ($ var) is true, (bool) ($ var) is false. And vice versa.
When is_null ($ var) is true, isset ($ var) is false. And vice versa.
$ I = $ j + 1;
Here is_null ($ j) is true (it can be understood that because isset ($ j) is false, because $ j is not declared in advance)
Note the following two points:
(1) empty () only detects variables and any non-variables will cause parsing errors. In other words, the following statement does not work: empty (addslashes ($ name )).
(2) isset () can only be used for variables, because passing any other parameter will cause a parsing error. To check whether a constant has been set, use the defined () function.Articles you may be interested in
Is_null, empty, and isset functions are difficult to implement...