Today, someone asked me what is the difference between isset and is_null. in the manual, the functions of isset and is_null are almost identical. Is isset the opposite alias of is_null? Well, there are many differences ~ Everything is different because is_null is a function, isset is a statement, isset is a statement, and echo, print
Today, someone asked me what is the difference between isset and is_null. in the manual, the functions of isset and is_null are almost identical. Is isset the opposite alias of is_null? Well, there are many differences ~ Everything is different because is_null is a function, isset is a statement, isset is a statement, and echo, print
Someone asked me what is the difference between isset and is_null today,
In the manual, isset and is_null have almost identical functions "..
Is isset the opposite alias of is_null?
Well, there are many differences ~
Everything is different because is_null is a function and isset is a statement.
Isset is a statement. Like echo and print, isset is a language structure of PHP itself.
Is_null is a function, which can be called as a variable function just like ordinary functions.
You may say, well, well, I know the difference between functions and statements, but what is the difference between TMD?
The so-called statement and language structure are the statements and identifiers supported by the language itself.
For example, for, foreach, and continue, they are "Erased" at the moment of syntax analysis (logically replaced.
Let's take a look at how the isset statement is erased during syntax analysis.
1. first, isset is recognized as T_ISSET identifier during lexical analysis. 2. in the syntax analysis stage, the isset ($ var) command is analyzed into an Opcode: ZEND_ISSET_ISEMPTY_VARS.
You can understand isset and think about the Macros in the C language, which have been expanded before compilation/execution.
Because of this, there will be the following differences in performance:
Because is_null is a function, it can be called as follows:
Because isset is a statement, it cannot be called like this.
Because is_null is a function, it can accept the return value of the function as a parameter, while isset is not (of course, If PHP wants to support it, it is also possible, but it will increase the complexity of the compilation phase ):
After talking about the shortcomings of so many issets, let's talk about its advantages:
Because isset is a statement, it is fast!
In the 10 million simple check statement loop, the comparison results are as follows:
Because isset is called isset, it does not produce NOTICE when detecting undefined variables:
So, when to use isset and when to use is_null, what suggestions do I have?
Hi, my advice is to use functions to do what functions should do ~, It sounds like nonsense?
Isset => is set? => Is the variable assigned a value (Declaration)
Is_null => is null? => Is the variable NULL?
In addition, if is_null is used, we recommend that you use "= NULL" instead. It not only has the same semantics and is_null, but also has the same results and speed as isset:
In the 10 million simple check statement loop, the comparison results are as follows:
Original article address: the difference between isset and is_null. Thank you for sharing it with the original author.