-1

I am in doubt after reading This Article. I had read on several forms and articles that php is an interpreted language, even i found the same thing with Stackoverflow but when i read it from here I got confused. Can anyone explain me about this with certain authenticated links or refrences.

Addition After 3 Comments:- The Article says:-

PHP became a compiled language in the year 2000, when PHP 4 was released for the first time. Until version 3, PHP source code was parsed and executed right away by the PHP interpreter.

Please Don't put your answers as such without having a look at the mentined article. I got the doubt after reading this article and i am much more courious about the content of this article,

Community
  • 1
  • 1
ScoRpion
  • 11,364
  • 24
  • 66
  • 89
  • I'm not an expert, but is the distinction just an interpreted language that is compiled at request time and each request time, whereas a 'proper' compiled language is pre-compiled to machine code and that machine code is then ran thereafter? – Martin Bean May 29 '12 at 11:40
  • The article you mention is about HipHop, a software that converts PHP to c, which is a compiled language. "Normal" PHP is still interpreted. – Sgoettschkes May 29 '12 at 11:40
  • "The idea of what is a compiler seems to be a subject that causes great confusion. Some people assume that a compiler is a program that converts source code in one language into an executable program. The definition of what is a compiler is actually broader than that." – PeeHaa May 29 '12 at 11:41
  • @Sgoettschkes I have added few lines to my question please have a look at it – ScoRpion May 29 '12 at 11:51
  • 2
    It's all about the definition of compiled vs. interpreted. If you take the definition from the article, then php is a compiled language. If you take the definition most of us have, it's an interpreted one. – Sgoettschkes May 29 '12 at 12:50

3 Answers3

5

It isn't.
The article you mention talks about HipHop which is Facebook's tool to compile PHP into C++ for faster execution.


Edit:

As explained in the article:

PHP became a compiled language in the year 2000, when PHP 4 was released for the first time. Until version 3, PHP source code was parsed and executed right away by the PHP interpreter.
The first phase parses PHP source code and generates a binary representation of the PHP code known as Zend opcodes

That means that the PHP code isn't parsed and executed directly, but compiled first, on the fly.
So yes, it is somehow compiled, but internally without the intervention of the user which makes it different than real compiled languages such as Java or C++.

That's my personal interpretation, feel free to comment if it's wrong.

Samy Dindane
  • 17,900
  • 3
  • 40
  • 50
  • Thanks for your response but I am not completely satesfied with your answer. I have added few lines from the artice, can you please justify these lines. – ScoRpion May 29 '12 at 11:50
  • I am not the master to prove you are wrong. but not yet completly satesfied. Thanks for you nice and valuable response – ScoRpion May 29 '12 at 12:19
  • It is somewhat similar to the bytecode in Java, but as long as there is no opcode-cache in place, this compiling takes place every. time. the script executes. – sinni800 May 29 '12 at 12:22
0

The article you are mentioning is about a project called HipHop which is not classic PHP.

HipHop will take your php project (php files) and generate another set of files in C++ that will have the same behavior.

Once the project is a C++ project, it becomes a project that needs compilation.

HipHop was created by facebook engineers to improve the performance of their code (they use PHP a lot) without the need of rewriting their whole stack in another language.

To clarify the quote that PHP is a compiled language since PHP4, it is true that since PHP4 the scripts are not executed as they are parsed : Each included file is pre-"compiled" to opCode and it is this opcode that is dynamically executed.

This 2-stage process has enabled the creation of specific opCode caching tools that can greatly improve the execution time of PHP. cf for instance http://xcache.lighttpd.net/

The opCode is executed by a "virtual machine" that knows how to interpret these opCodes (a bit like the Java Virtual Machine).

HipHop leads to additional performance because this opCode layer is bypassed.

Jerome WAGNER
  • 21,986
  • 8
  • 62
  • 77
0

Related to this:

PHP became a compiled language in the year 2000, when PHP 4 was released for the first time. Until version 3, PHP source code was parsed and executed right away by the PHP interpreter.

this is correct too, but you have to look at the definitions of a "compiled" or "interpreted" to really grasp what this means. The distinction is really not that clear-cut. What is meant by compilers is commonly thought of as software transforming source code to executable form. However, more formal definition of a compiler is something transforming one form of representation into another form, like also mentioned in the article.

Interpreter is a piece of software that actually does the actions that are defined in the source code, instead of (just) transforming. Based on that definition, PHP is still (by default, excluding things like HipHop) interpreted. The change that was done on release of PHP4 was that the source code is not directly parsed and executed, but first compiled to an intermediary representation (in this case opcodes) in-memory by the interpreter, and then executed. That kind of "compilation" is what pretty much all modern interpreters of different languages do nowadays in some form or another.

eis
  • 51,991
  • 13
  • 150
  • 199
  • To make it a little easier to grasp: Interpreters go through code line-by-line and execute it while reading it. Compilers go through code line-by-line, transforming it into a different representation, such as machine code (for compilers like the C compiler) or bytecode (for compilers like the Java compiler). – sinni800 May 29 '12 at 12:24
  • Machine code is just the typical output of a compiler. What happens inside the compiler or an interpreter is typically transformation into intermediate representation - but regardless, interpreters will execute that intermediate representation, whereas compilers use that to output something different than the original, without actually doing the stuff given in the code. – eis May 29 '12 at 12:31