Is php compiled or interpreted?
The PHP language is interpreted. 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
Php is an interpreted language. It can be compiled to native bytecode by third party-tools though.
Its interpreted. So keep that in mind when you put too many comments in your code...
This is a meaningless question.
PHP uses yacc (bison), just like gcc. Both php and gcc read your source code and produce an abstract syntax tree. PHP then walks the tree to run your program; gcc walks the tree and outputs assembly.
Calling one "interpreted" and the other "compiled" is meaningless. They are both run through a "compiler", after all.
You should actually ask the question you want to ask instead. ("Do I pay a performance penalty as PHP recompiles my source code for every request?", etc.)
(Edit: yacc is a "compiler compiler". The output of yacc is a compiler. The output of a compiler is "compiled". PHP is parsed by the output of yacc. So it is, by definition, compiled.)
In generally it is interpreted, but some time can use it as compiled and it is really increases performance. Open source tool to perform this operation: http://www.phpcompiler.org/
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.
A definition of a programming language doesn't mandate a "compiled" or "interpreted" form even though one can be much easier to implement based on its design. Theoretically you can write a C interpreter and a Python compiler too.
And "compiled/interpreted" terms are attributed to different things in answers given to this question. What I understand is you're asking if Zend's PHP implementation is compiled into native code or not, and the answer is no. Your PHP code is converted into bytecode and interpreted by an engine, not directly executed by CPU.
But more importantly, it doesn't mean much. You are asking this question because you're curious about one performance point. You want to know if PHP is fast or slow, based on compiled and interpreted status. This is a common mistake done by beginners. For instance, a badly compiled program can be much slower than a finely implemented interpreter. A bad runtime or library can make your native code sluggish enough to be beaten by slowest interpreter.
I assumed that your point was performance because you mentioned you were a beginner but of course you could care about other things too. Native code also makes reverse engineering harder. However I'd like to stay on performance path.
Native code mostly gets useful in computation. When serving web pages if what you do is only a list of system calls (connect to MySQL server, pull data, write to client's socket stream) with small logic in between, the performance gap can actually be small between native and compiled code.
Native is almost always faster but such tradeoff decisions are made to get other benefits from interpretation, such as easier deployment/maintenance, less memory footprint, straightforward cross-platform compatibility, dynamic type system, runtime optimizations etc.
As a final note, there is a PHP compiler called phc.