php: about parsing and interpreting process -


i see parse or compile in tech articles. want know how php works . found out php interpreted language, not compiled. googled online parse, interpret , compile, still not clear on whole process. below example php code:

<?php $str1="hello world!"; $str2="what nice day!"; echo $str1 . " " . $str2; ?>   

output:

hello world! nice day!  

can explain whole process(parse, interpret...) source code output? thanks

a high level , not complete overview of process:

  1. the source code tokenized, i.e. broken down individual parts , these parts "classified". $str1 variable, = operator, "hello world!" string literal, ; statement terminator etc.
  2. the tokens transformed abstract syntax tree, i.e. tokens "grouped meaning". we have expression = assignment operator first operand $str1 , second operand string literal "hello world!".

    these 2 steps complete parsing.

  3. the individual parts in syntax tree translated low-level machine instructions, e.g. reserve memory store "hello world!" , create symbol $str1 reference it.

    that description still pretty high level "machine instructions" btw , use here keep simple.

    this compilation step.

  4. the instructions executed.

the distinction between "interpreted" languages , "compiled" languages arbitrary. language needs parsed , translated machine instructions, compilation. "real" compiled languages must compiled binary executable first manually executed. php both in 1 go, throws executable code away. that's interpreted code is; it's parsed , compiled on fly right source. there byte code caches php cache machine code, not requiring php re-compile same code on , over.

"real" compilers serve other purposes: can detect basic or pretty complex problems during compilation analyzing code , refuse compile it; since php winging goes along cannot catch these kinds of problems during compilation , crop while code executing, requires different kind of error handling philosophy compiled languages do. "real" compilers can spend more time on optimizing code , potentially make execute faster; since php on fly doesn't spend if time on optimizing code, since make slower.

btw, php language neither interpreted nor compiled. it's language. standard, official php runtime environment what's interpreting language. there php compilers, famously facebook's hiphop, compile php code executable binaries.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -