In-depth understanding of PHP principles, error suppression, and embedded HTML

Source: Internet
Author: User
PHP supports embedded HTML. how does one deal with HTML outside the PHP tag in the PHP file? What is the difference between HTML and HTML? PHP provides an error blocker & amp; rsquo; @ & amp; #39;. how does it block error output? When should I... "> <LINKhref =" http://www.php

PHP supports embedded HTML. how does one deal with HTML outside the PHP tag in the PHP file? What is the difference between HTML and HTML?

PHP provides an error blocker '@'. how does it block error output? When should I use it again?

This is a common question raised by some netizens over the past two days. today, I will simply answer this question and read it later.

Php file embedded HTML processing method

In PHP, all characters outside the tag are translated into T_INLINE_HTML tokens during lexical analysis. during syntax analysis, all T_INLIE_HTML characters are allocated with ZEND_ECHO output.

That is to say:

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

An OPLINE: T_ECHO will be generated, and the operand is "laruence ";

The above code is actually the same as the following:

  1.   
  2. While ($ con ){
  3. Echo "laruence ";
  4. }
  5. ?>

However, note that all characters outside the PHP tag are segmented in units of 400 characters during lexical analysis. for example:

  1.   
  2. If (1 ){
  3. ?>
  4. Laruence large numbers of large numbers laruence
  5. }
  6. ?>

In the above code, the tag contains 531 characters (including space and carriage return) and is divided into two T_INLINE_HTML outputs.

Error blocker

We know that in PHP, the error message can be silent through the error blocker. how does it work?

During syntax analysis,:

  1.   
  2. @ Include ('file ');
  3. ?>

Two Opline (operations) will be inserted before and after the include statement respectively. These two operations are done respectively:

1. save the current error_reporting value and set error_reporting (0); // disable the error output.

2. restore the previously saved error_reporting value.

That is to say, the above code is similar to the following code:

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

In addition, let's talk about the question: "When Will error suppression be applied ?", My personal suggestion is that if an error in this statement does not affect you much and you do not care about the error, you will not arrange additional logic to handle the error, then you can use error suppression. otherwise, use additional logic to identify errors.

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.