Deep understanding of the PHP principle of error suppression and embedded HTML

Source: Internet
Author: User
Tags include php file

PHP supports inline HTML, so what happens to HTML in PHP files outside of PHP tags? What is the difference between it and direct output HTML?

PHP provides an error suppressor ' @ ', how does it block the error output? When should I use it?

This is the two days some netizens mentioned common problems, today, simply overall answer, prepare up-and browsing.

PHP file embedded HTML processing method

In PHP, all the characters outside the label, in the lexical analysis process, will be translated into t_inline_html token, in the grammar analysis, all t_inlie_html will be assigned Zend_echo output.

Other words:

    1. <?php
    2. while ($con) {
    3. ?>
    4. Laruence
    5. }
    6. ?>

Generates a opline:t_echo, and the operand is "laruence";

As a result, the above code, in fact, is the same as the following result:

    1. <?php
    2. while ($con) {
    3. echo "Laruence";
    4. }
    5. ?>

But there is a point to note is that for the characters outside the PHP tag, in the lexical analysis process, will be 400 characters in the unit, such as:

    1. <?php
    2. if (1) {
    3. ?>
    4. 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 LA Ruence laruence laruence laruence laruence
    5. }
    6. ?>

In the above code, there are 531 characters outside the label (including a space carriage return), which is divided into two t_inline_html outputs.

Error Suppressor

We know that in PHP, you can use the error suppressor to silence the error hint, so what's the way it works?

In the process of parsing, for:

    1. <?php
    2. @include (' file ');
    3. ?>

Inserts two opline (operations) before and after the include statement, each of which does the following:

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 is similar to the following code:

    1. $old = error_reporting (0);
    2. Include (' file ');
    3. Error_reporting ($old);

In addition, say a digression: "When is the application of error suppression?", my personal suggestion is that if this statement does not affect you very much, you do not care what the error is, and you do not arrange additional logic to handle the error, then you can use error suppression. Otherwise, you can use additional logic to determine the error.







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.