In-depth understanding of the PHP principles of error suppression and embedded HTML parsing _php tutorial

Source: Internet
Author: User
PHP provides an error suppressor ' @ ', and how does it prevent error output? When should I use it?
This is the two days some netizens mentioned the common problem, today, simply answer the whole, prepared Yimeimei flip.
How to handle the HTML embedded in PHP files
In PHP, all characters outside the label, in the lexical analysis process, will be translated into t_inline_html token, when parsing, all the t_inlie_html will be assigned Zend_echo output.
Other words:
Copy CodeThe code is as follows:
while ($con) {
?>
Laruence
}
?>

Generates a opline:t_echo, and the operand is "laruence";
As a result, the above code is actually the same as the following result:
Copy CodeThe code is as follows:
while ($con) {
echo "Laruence";
}
?>

But one of the things to note is that for characters outside of the PHP tag, the lexical analysis will be divided in 400 characters, such as:
Copy CodeThe code is as follows:
if (1) {
?>
Laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence LaRue nce laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence L Aruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence Laruen Ce laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence laruence LA Ruence laruence laruence laruence laruence
}
?>

In the above code, there are 531 characters outside the label (including the space carriage return), which will be divided into two t_inline_html output.
Error suppressor
We know that in PHP, you can use the error suppressor to silence the error hint, so what is the way it is?
In the process of parsing, for:
Copy CodeThe code is as follows:
@include (' file ');
?>

Two opline (operations) are inserted before and after the include statement, each of which does the following:
Copy CodeThe 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, the above code, in fact, resembles the following code:
Copy CodeThe code is as follows:
$old = error_reporting (0);
Include (' file ');
Error_reporting ($old);

In addition, say a digression: "When to apply error suppression?", my personal advice is that if this statement goes wrong, you don't care about what the error is, and you don't schedule additional logic to handle the error, then you can use error suppression. Otherwise, please use additional logic to determine the error.

http://www.bkjia.com/PHPjc/323222.html www.bkjia.com true http://www.bkjia.com/PHPjc/323222.html techarticle PHP provides an error suppressor ' @ ', and how does it prevent error output? When should I use it? This is the two days some netizens mentioned common problems, today ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.