Home > Backend Development > PHP Tutorial > In-depth understanding of PHP principles: error suppression and embedded HTML analysis_PHP Tutorial

In-depth understanding of PHP principles: error suppression and embedded HTML analysis_PHP Tutorial

WBOY
Release: 2016-07-21 15:30:19
Original
854 people have browsed it

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 I’ll just give the overall answer for future reference.
How to handle HTML embedded in PHP files
In PHP, all characters outside the tags will be translated into T_INLINE_HTML token during the lexical analysis process, and will be translated into T_INLINE_HTML token during the syntax analysis. When >while($con) {
?>

laruence } ?>
An OPLINE will be generated: 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 code

The code is as follows:

while($con) {
echo "laruence";
} ?> But one thing to note is that characters outside of PHP tags will be divided into units of 400 characters during the lexical analysis process, for example:


Copy 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 label (including spaces and carriage returns), which will be divided into two T_INLINE_HTML output.
Error suppressor
We know that in PHP, error suppressors can be used to silence error prompts, so what method is used?
In the process of syntax analysis, for:



Copy code
The code is as follows:


@include('file');
?>
will insert two Oplines (operations) before and after the include statement. These two operations are performed separately:
Copy code

The code is as follows:

1. Save the current error_reporting value and set error_reporting(0); //Close error output
2. Restore the previously saved error_reporting value
In other words, the above code is actually similar to the following code:
Copy the code

The code is as follows:

$old = error_reporting(0);
include('file');
error_reporting($old);
Also, a digression: "When should it be applied? What about error suppression?", 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 errors.
http://www.bkjia.com/PHPjc/323222.html

www.bkjia.com

true

http: //www.bkjia.com/PHPjc/323222.html

TechArticle

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template