Page 3 of 4

Re: Is PHP code interpreted or compiled ?

Posted: Tue Feb 23, 2010 4:15 pm
by VladSun
I thought there are two stages - the compiler one and linker one...
There might be a third (first ;)) stage - a translator.
I think an interpreter is just a combination of some of these.

Re: Is PHP code interpreted or compiled ?

Posted: Tue Feb 23, 2010 5:36 pm
by josh
Compile - convert from one format to another
Native Executable - what you guys are confused over thinking both terms are one in the same.


If I constructed a machine which can run PHP's op code language as it's native machine code, would PHP magically be re-classified? I think not.

I can add the integers 1+1 and say I compiled them into the integer 2. I would not be wrong. (well technically I de-compiled but lets not miss the point)

Your guy's definition of compile is stupid. You have to make it open ended. Give me any compiled language and I will tell you a machine it is not "native" on. Therefore you must leave the definition open ended. Compilers compile from one language to another. Period.

I would say "PHP is a language that compiles into a standardized op code which are then interpreted by a server module designed to interpret said op code". I bet your java IDE still has a "compile" button too.

From wiki (the end of all of end all.. sarcasm)

Compiled versus interpreted languages
Higher-level programming languages are generally divided for convenience into compiled languages and interpreted languages. However, in practice there is rarely anything about a language that requires it to be exclusively compiled, or exclusively interpreted; ..snip..Modern trends toward just-in-time compilation and bytecode interpretation at times blur the traditional categorizations of compilers and interpreters.
If Alan Turing were here he'd say you guys are talking about "swimming" submarines. (You're simply talking about a concept that makes no sense to begin with). A language is just a language. It is the words on your screen, not the php.exe that is the ONE POSSIBLE implementation of that language. Facebook just made a PHP compiler. It compiles from PHP to native machine code thru an intermediate C++ format. Also what about zend opcode cache? Thats another implementation of PHP (proving the language and the implementation are not a 1:1 relationship).How many freaking C++ compilers are there for example?. The language and the language's possible implementations are two different concepts. You can only classify the implementation as compiled/not compiled. And even then it doesn't make sense to do so.

Proof is in the pudding folks.

Re: Is PHP code interpreted or compiled ?

Posted: Tue Feb 23, 2010 6:21 pm
by VladSun
While I agree with you, I think you miss some terminology...
What is the meaning of the word "format" in your "Compile - convert from one format to another" sentence?!?
I think sometimes you meant "translator" instead of "compiler" ...
Out definition of compile is not stupid - you mix compilation with cross-compilation. One does compile something for a particular target architecture (if it is supported by the compiler)...

Re: Is PHP code interpreted or compiled ?

Posted: Tue Feb 23, 2010 6:34 pm
by Weirdan
josh wrote:I would say "PHP is a language that compiles into a standardized op code which are then interpreted by a server module designed to interpret said op code".
You've nailed it (except you need to specify the particular implementation, otherwise this statement is incomplete).

Re: Is PHP code interpreted or compiled ?

Posted: Tue Feb 23, 2010 7:55 pm
by josh
Vladsun, in order to be a compiler it doesn't have to output native machine code. Period. That is just how I personally choose to interpret the definition. If the definition omits something, it probably omitted it for a reason. Nowhere does it say it has to compile to anything specific.

@weirddan yes for the purposes of not getting overly anal we can assume when we talk about PHP as a language we also assume we are using the core source code w/ an apache module. The intention of me brining up the difference between language and an implementation is not to argue with anybody who says PHP is not compiled (because they are also right, in their own way), but rather prove that the OP asked a trick question to begin with

Re: Is PHP code interpreted or compiled ?

Posted: Wed Feb 24, 2010 9:20 am
by alex.barylski
I think it depends entirely on the implementation of the system. From what I recall, some C/C++ builders have more steps than others, for example, some might implement a preprocessor, compiler, linker and maybe even an assembler, whereas others are one or two pass implementations.

Cheers,
Alex

Re: Is PHP code interpreted or compiled ?

Posted: Wed Feb 24, 2010 12:05 pm
by VladSun
josh wrote:Vladsun, in order to be a compiler it doesn't have to output native machine code. Period.
I didn't say it always has to be a machine code output. You said "Give me any compiled language and I will tell you a machine it is not "native" on. " That's what I argued about. Don't blame me for words said by yourself.

// flame on

http://en.wikipedia.org/wiki/Interpreted_language
...
http://en.wikipedia.org/wiki/Scripting_language
...
http://en.wikipedia.org/wiki/Compiled_language
=>
A compiled language is a programming language whose implementations are typically compilers (translators which generate machine code from source code), and not interpreters (step-by-step executors of source code, where no translation takes place).
Apparently, people distinguish between compiled, interpreted and scripting *languages*...

Re: Is PHP code interpreted or compiled ?

Posted: Wed Feb 24, 2010 2:09 pm
by AbraCadaver
One horse is dead, so on the Facebook HipHop topic: viewtopic.php?f=6&t=112224&p=595391#p595391

Re: Is PHP code interpreted or compiled ?

Posted: Wed Feb 24, 2010 2:36 pm
by josh
"whose implementations are typically"
Did you miss that part?

Also the page you linked has no sources. At all. Like I already said some people may find it useful to classify the languages, but its a misnomer and its pointless. PHP comes with compilers *and* interpreters. Like I said if you want to get technical then everyone is right. Wouldn't that make the terms pointless tho? Linking source-less wiki pages changes nothing. Some people classify languages into ones that are "pretty" and ones that are not, that is an equally as pointless and informal classification system.

@Abra Nice article. Direct linking http://www.phpclasses.org/blog/post/117 ... mance.html

Re: Is PHP code interpreted or compiled ?

Posted: Wed Feb 24, 2010 3:33 pm
by VladSun
josh wrote:"whose implementations are typically"
Did you miss that part?
Do you really think I missed that part?!?

What about the "PHP is a compiled language since PHP 4.0" in the PHP classes blog you pointed to??? WTH does it mean???

Re: Is PHP code interpreted or compiled ?

Posted: Wed Feb 24, 2010 3:55 pm
by VladSun
I've gone trough asm, c/c++, Pascal ... PHP, Perl,...C#, even some CLI experience. So, I have a pretty good idea what I would call a compiled, interpreted or a scripting language.

Though, I have compiled Perl code several times, I'll always call Perl an interpreted language...

So, as I said, I do agree with you that compiled/interpreted/etc. language classification has become somehow meaningless, but it will take some time before it's accepted by the IT community (including me).

Re: Is PHP code interpreted or compiled ?

Posted: Wed Feb 24, 2010 4:09 pm
by josh
VladSun wrote:What about the "PHP is a compiled language since PHP 4.0" in the PHP classes blog you pointed to??? WTH does it mean???
Nothing really. But the compilers it talks about are useful. Languages and implementations (compilers or interpreters) are totally distinct.
VladSun wrote:Though, I have compiled Perl code several times, I'll always call Perl an interpreted language...
And I call anything not bracketed "ugly", its just an opinion. One that many people might disagree with. If you have compiled and interpreted code in that language, then obviously the terms are moot, or the language is both. In either of those cases the terms have lost all practical meaning. You call it interpreted because that is the method you associate with historically. Someone who has always compiled it might call it compiled.
VladSun wrote:quote language classification has become somehow meaningless, but it will take some time before it's accepted by the IT community (including me).
They are terms left over from previous decades before people at large started to grasp the true portability of languages.

Theres no such thing as an "interpreted languages", only interpreters.

Re: Is PHP code interpreted or compiled ?

Posted: Mon Mar 01, 2010 4:39 pm
by M2tM
Compilers are programs which transform code from one form to another.

PHP is as has been said, a language compiled into an intermediary language which is then interpreted. Compilers which turn PHP into C/C++ programs exist such as HipHop and PHC.

These implementations typically have problems with really dynamic aspects such as the eval command because things like that need a run-time interpreter of the language to execute.

Of course someone would be capable of writing a PHP to C++ (or machine code) compiler that also include a runtime interpretation implementation of eval, just that so far I am unaware of any compilers that translate PHP into anything other than opcode which supports this feature. It would basically mean implementing the language twice. Until all the features of PHP are truly implemented in a compiler of the language into static bytecode similar to that of C/C++, as arbitrary as the term may sound, PHP is basically an interpreted language, and its opcode language certainly is.

"In computer programming, an interpreted language is a programming language whose programs are not directly executed by the host cpu but rather executed (or said to be interpreted) by a software program known as an interpreter. The source code of the program is often translated to a form that is more convenient to interpret, which may be some form of machine language for a virtual machine. Theoretically, any language may be compiled or interpreted, so this designation is applied purely because of common implementation practice and not some underlying property of a language."

http://en.wikipedia.org/wiki/Interpreted_language

Re: Is PHP code interpreted or compiled ?

Posted: Mon Mar 01, 2010 7:40 pm
by josh
M2tM wrote:just that so far I am unaware of any compilers that translate PHP into anything other than opcode which supports this feature.
Are there even compilers in any language that support eval? C++ doesn't have an eval function, it is still compiled. Why must a PHP->C++ compiler support eval if C++ does not? Sounds like an arbitrary requirement.

Re: Is PHP code interpreted or compiled ?

Posted: Mon Mar 01, 2010 8:22 pm
by M2tM
josh wrote:
M2tM wrote:just that so far I am unaware of any compilers that translate PHP into anything other than opcode which supports this feature.
Are there even compilers in any language that support eval? C++ doesn't have an eval function, it is still compiled. Why must a PHP->C++ compiler support eval if C++ does not? Sounds like an arbitrary requirement.
Why -must- a PHP compiler support eval? I don't suppose it must except that it is in the language. I do not understand what point you are trying to make by suggesting C++ does not support an eval function, the language was never specified to include dynamic interpretation of itself as PHP was.

My only point was really that PHP is -so far- a primarily interpreted language by all the definitions we have available. Attempts at creating compilers for the language have -thus far- been limited in a number of respects, the eval example was the most potent one I could think of. I do not personally make much use of the function, but the implications of the eval function are huge and easy to illustrate why PHP is not often approachable as a compiled language. The language wasn't designed with compiling in mind (some would argue it was hardly "designed" at all) and any compilers built to do the task are done with great effort and a few necessary missing pieces of the language.

Conditional declaration of functions is another example. There are more. How do you write a static compiler for this:

if($runtimeValue == true){
function f(){return '1';}
}else{
function f(){return '2';}
}

Conditional declaration like this can get a bit messy, you may come up with solutions, but it's tricky at least.

There are many problems with current implementations of PHP compilers, none of them are really viable for execution on code not written with those limitations in mind. Most of the code written today is written for the standard PHP interpreters and my only point was not that PHP is only an interpreted language, but that it is so often interpreted that to call it anything else would be misleading.