: This article mainly introduces the php parsing process. if you are interested in the PHP Tutorial, you can refer to it. We all know the execution process of PHP scripts. First, the Zend Engine compiles the PHP source code into an opcode sequence, and then the Zend VM will explain the execution. Generally, the process of compilation is to perform lexical analysis and syntax analysis first, and then compile. After syntax analysis, there is an abstract syntax Tree (AbstractSyntax Tree or AST), which is the output of syntax analysis, the subsequent compilation process is based on the AST by the compiler.
However, PHP is quite special. the Zend Engine directly produces opcode after syntax analysis and does not generate AST. The biggest advantage of doing so is to speed up the compilation process. The disadvantage is that it loses some freedom, is difficult to optimize, and leads to complicated compilation program logic. A wiki on the official PHP website discusses introducing AST during PHP compilation. of course, it is very difficult to implement it.
We generally do not have access to the PHP compilation process at ordinary times, but AST is a useful thing. many tools in our work usually contain AST, such as PHP_CodeSniffer, PHP_Depend, ZendStudio, and PDT, when you need to analyze the source code, you need AST to help you more or less.
Next, let's take a look at the PHP 7 and php5 compilation processes,
The above describes the php parsing process, including the content, and hope to help those who are interested in the PHP Tutorial.