Home  >  Article  >  Backend Development  >  http://www.12306.cn/mormhweb/k In-depth understanding of PHP principles, error suppression and embedded HTML analysis

http://www.12306.cn/mormhweb/k In-depth understanding of PHP principles, error suppression and embedded HTML analysis

WBOY
WBOYOriginal
2016-07-29 08:45:041186browse

PHP provides an error suppressor '@'. How does it prevent error output? When should I use it?
This is a common problem mentioned by some netizens in the past two days. Today I will simply summarize it. Answer for future reference.
How to handle embedded HTML in PHP files
In PHP, all characters outside the tags will be translated into T_INLINE_HTML tokens during the lexical analysis process. During the syntax analysis, all T_INLIE_HTML will be assigned ZEND_ECHO output.
That is to say:

Copy the code The code is as follows:


while($con) {
?>
laruence
}
?>


will generate an OPLINE: T_ECHO, and the operand is "laruence";
As far as the result is concerned, the above code is actually the same as the following result:

Copy the code The code is as follows:


while($con) {
echo "laruence";
}
?>


But one thing to note is that for characters outside the PHP tag, during the lexical analysis process, It will be divided into units of 400 characters, for example:

Copy the code The code is as follows:


if(1) {
?>
laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence
}
?>


In the above code, there are 531 characters outside the tag (including spaces and carriage returns), which will be divided into two T_INLINE_HTML outputs.
Error suppressor
We know that in PHP , you can silence the error prompt through the error suppressor, so in what way?
During the syntax analysis process, for:

Copy the code The code is as follows:


@ include('file');
?>


will insert two Opline (operations) before and after the include statement. These two operations are performed respectively:

Copy the code The code is as follows:


1 . Save the current error_reporting value and set error_reporting(0); //Turn off error output
2. Restore the previously saved error_reporting value


In other words, in fact, the above code is similar to the following code:

Copy the code The code is as follows:


$old = error_reporting(0);
include('file');
error_reporting($old);


In addition, let me make a digression: "When should error suppression be applied? What?", my personal suggestion is that if this statement goes wrong and it has little impact on you, you don't care what the error is, and you won't arrange additional logic to handle this kind of error, then you can use error suppression. . Otherwise, please use additional logic to determine the error.

The above has introduced the http://www.12306.cn/mormhweb/k in-depth understanding of PHP principles, error suppression and embedded HTML analysis, including the content of http://www.12306.cn/mormhweb/k. I hope Helpful for those who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn