Is PHP compiled or interpreted?
Both. PHP is compiled down to an intermediate bytecode that is then interpreted by the runtime engine.
The PHP compiler's job is to parse your PHP code and convert it into a form suitable for the runtime engine. Among its tasks:
- Ignore comments
- Resolve variables, function names, and so forth and create the symbol table
- Construct the abstract syntax tree of your program
- Write the bytecode
Depending on your PHP setup, this step is typically done just once, the first time the script is called. The compiler output is cached to speed up access on subsequent uses. If the script is modified, however, the compilation step is done again.
The runtime engine walks the AST and bytecode when the script is called. The symbol table is used to store the values of variables and provide the bytecode addresses for functions.
This process of compiling to bytecode and interpreting it at runtime is typical for languages that run on some kind of virtual runtime machine including Perl, Java, Ruby, Smalltalk, and others.
PHP is an interpreted language. The binary that lets you interpret PHP is compiled, but what you write is interpreted.
You can see more on the Wikipedia page for Interpreted languages