The difference between the two functions: die and exit. most of the "standard answer" is that die exits and releases the memory, while exit exits but does not release the memory.
The difference between the two functions: die and exit. most of the "standard answer" is that die exits and releases the memory, while exit exits but does not release the memory.
This explanation is obviously wrong. The PHP Manual already says "die-Equivalent to exit (). this language construct is equivalent to exit (). the two are just alias relationships, and they are all the same.
But I am still curious. I decided to look for clues from the source code to see how php handles this "Alias ".
First of all, it should be clear that both die and exit are "language construct" rather than functions. on the Internet, there are also many saying that a certain person has a return value as a function, and a certain person has a structure without a return value, many beginners cannot understand the differences between language structures and functions. in plain words, the language structure can be understood as an identifier of the syntax itself. Like +,-, *, and/are also language structures. if, else, for, and while are language structures. Is part of the syntax itself. Any language will have these things, because the computer does not think that ++ should do addition. This requires the compiler to convert the machine code to the instruction set that can be recognized by the cpu.
The entire process for php to execute the source code is: first, according to the definition in zend_language_scanner.l, convert the language structures such as echo and if in the source code into tokens such as T_ECHO and T_IF, in addition, spaces in the source code are removed to comment out the characters irrelevant to the program logic ., Some short expressions are formed, which is the lexical analysis stage. The tokens are then converted to op code according to the token defined in zend_vm_opcodes.h. Then execute the op code in one row.
The above describes the php compilation and execution processes and the definition of the language structure. Next, go to the topic.
We should also remember that php has many alias functions, such as implode and join. Both the alias function and the alias language structure are the same in terms of actual results, but the source code processing methods are certainly different.
Let's take a look at how the alias language structure is handled. let's look at the alias function later.
Zend_language_parser.c defines a macro
# Define T_EXIT 300
An enum is also defined, which also contains
Enum yytokentype {
...
T_EXIT = 300,
....
}
Here we can tell you that the token T_EXIT has a code of 300.
Let's look at zend_language_scanner.l, which contains several lines of code.
"Exit "{
Return T_EXIT;
}
"Die "{
Return T_EXIT;
}
Obviously, when php performs lexical analysis, the T_EXIT token will be returned regardless of exit or die. Here we can prove that the internal processing of die, exit, and php is exactly the same.
You can also use the following php code to determine:
Var_dump (token_get_all (" "));
In the returned result, the token code corresponding to die and exit is 300.
Now, I think you can confirm the problem about die and exit, but the names are different and the effects are the same. there is no such problem as uninstalling or uninstalling the memory.