PHP执行这段代码会经过如下4个步骤(确切的来说,应该是PHP的语言引擎Zend)
1.Scanning(Lexing) ,将PHP代码转换为语言片段(Tokens)
2.Parsing, 将Tokens转换成简单而有意义的表达式
3.Compilation, 将表达式编译成Opocdes
4.Execution, 顺次执行Opcodes,每次一条,从而实现PHP脚本的功能。
将一段PHP代码 Scanning成Tokens;
var_dump(token_get_all(‘<#php echo “Hello World”; #>’));
Array(
[0] => Array(
[0] => 376
[1] => <#php
[2] => 1 )
[1] => Array(
[0] => 319
[1] => echo
[2] => 1 )
[2] => Array(
[0] => 379
[1] =>
[2] => 1 )
[3] => Array(
[0] => 318
[1] => “Hello World”
[2] => 1 )
[4] => ;
[5] => Array(
[0] => 379
[1] =>
[2] => 1 )
[6] => Array(
[0] => 378
[1] => #>
[2] => 1 )
)