Page 2 of 4
Re: Is PHP code interpreted or compiled ?
Posted: Mon Feb 22, 2010 4:26 pm
by Jenk
This is not a default option with PHP, PHP is an interpreted language.. you need a 3rd party compiler plugin to do that. Why is it so hard to accept that PHP is an interpreted language?

Re: Is PHP code interpreted or compiled ?
Posted: Mon Feb 22, 2010 4:35 pm
by pickle
Yes, you can write a compiler for PHP. You can also write an interpreter for Java/C++/any other "compiled" language. For most applications, and right out of the box, PHP is interpreted.
Re: Is PHP code interpreted or compiled ?
Posted: Mon Feb 22, 2010 6:52 pm
by Weirdan
Jenk wrote:Why is it so hard to accept that PHP is an interpreted language?

Because it's not true to start with, and also because it's meaningless to classify languages on this basis.
Re: Is PHP code interpreted or compiled ?
Posted: Tue Feb 23, 2010 3:37 am
by Jenk
Er, it
is true.. PHP is an interpreted language, because you do not compile it once, then run it many times. Every time it is run, it is interpreted. There is no "class" file or "dll" or "so" file like with C/C#/every-other-compiled-language. It is interpreted from source (*.php file)
every time it is run. PHP is an interpreted language. It's also certainly not meaningless.
http://2bits.com/articles/php-op-code-c ... -site.html
http://en.wikipedia.org/wiki/Interpreted_language
PHP is listed as an interpreted language there, too..
Re: Is PHP code interpreted or compiled ?
Posted: Tue Feb 23, 2010 3:38 am
by timWebUK
Thought this was interesting...
"Since PHP 4, the PHP parser compiles input to produce bytecode for processing by the Zend Engine, giving improved performance over its interpreter predecessor.[31]"
http://en.wikipedia.org/wiki/Php#Usage
Re: Is PHP code interpreted or compiled ?
Posted: Tue Feb 23, 2010 4:24 am
by Weirdan
Jenk wrote:Er, it is true.. PHP is an interpreted language, because you do not compile it once, then run it many times. Every time it is run, it is interpreted. There is no "class" file or "dll" or "so" file like with C/C#/every-other-compiled-language. It is interpreted from source (*.php file) every time it is run. PHP is an interpreted language.
The problem with your argument is that you're mixing up the language itself with its most common implementation. Would providing a link to a php compiler prove you're wrong? It would, in my book, but then you would argue it's not
that php you had in mind, that the only 'right' php is that released by the PHP Group, that the 'right' php does not store the bytecode
out-of-the-box, etc.
Basically I'm making my argument on the ground that it's possible to create a configuration where PHP source is compiled once and run many times (and this configuration is quite common in fact). This proves that PHP
as a language is not inherently interpreted, as do roadsend's pcc compiler and Facebook's HipHop compiler.
Re: Is PHP code interpreted or compiled ?
Posted: Tue Feb 23, 2010 5:19 am
by Jenk
I can't believe you are arguing on the basis that when using a modified PHP compiler it is no longer an interpreted language (even though it still is, as as soon as the source is changed it is interpreted again)
Honestly, look at your own argument... I could modify my car to have 20 doors, but it is a 3 door car when sold to me. PHP is interpreted, by the definition of "Interpreted language".
Re: Is PHP code interpreted or compiled ?
Posted: Tue Feb 23, 2010 5:47 am
by Weirdan
Jenk wrote:Honestly, look at your own argument... I could modify my car to have 20 doors, but it is a 3 door car when sold to me. PHP is interpreted, by the definition of "Interpreted language".
Well, and look at yours - you're saying there are no cars with 20 doors just because you've got the one with 3 doors.
C++ is still C++, regardless of whether you use gcc, mingw, MSVC or UnderC. The point is, there is PHP language which has multiple implementations. One of them happens to look like interpreter, even though it's not an interpreter in a classic sense under the hood. As we established earlier people usually don't call C++ an interpreted language, even though C++ interpreters exist. Yet you insist on calling PHP an interpreted language on that same basis - just because
one of implementation
in default configuration looks like it is interpreted to you.
Re: Is PHP code interpreted or compiled ?
Posted: Tue Feb 23, 2010 6:15 am
by Jenk
No, I'm not saying there are no 20 door cars, I'm saying my type of car is not a 20 door car, even after I have modified it to have 20 doors. It's still a 3 door car, and is marketed as such.
If you download PHP from PHP.net, you don't get opcaching, you don't get "compilation", you get what everyone expects of PHP - and interpreted language. There are opcache compilers available.
C++ is a compiled language, as you must use something like GCC to compile it before you can even try to run it. There are interpreters available.
Re: Is PHP code interpreted or compiled ?
Posted: Tue Feb 23, 2010 6:30 am
by Weirdan
Jenk wrote:No, I'm not saying there are no 20 door cars, I'm saying my type of car is not a 20 door car, even after I have modified it to have 20 doors. It's still a 3 door car, and is marketed as such.
To make it clear I was drawing the analogy between transportation devices and languages. Helicopter (C++) is still a helicopter, regardless of whether it's from Sikorski or Kaman or some other manufacturer. Car (PHP) is a car, regardless of whether it's Fiat or Maserati and whether your particular car has spoilers (extensions) installed.
Jenk wrote:If you download PHP from PHP.net
And what if you download PHP from roadsend.com ?
Re: Is PHP code interpreted or compiled ?
Posted: Tue Feb 23, 2010 9:23 am
by AbraCadaver
Jenk wrote:I can't believe you are arguing on the basis that when using a modified PHP compiler it is no longer an interpreted language (even though it still is, as as soon as the source is changed it is interpreted again)
Honestly, look at your own argument... I could modify my car to have 20 doors, but it is a 3 door car when sold to me. PHP is interpreted, by the definition of "Interpreted language".
I don't think I've ever seen a 3 door car. What is it?
Re: Is PHP code interpreted or compiled ?
Posted: Tue Feb 23, 2010 9:31 am
by Weirdan
AbraCadaver wrote:I don't think I've ever seen a 3 door car. What is it?
two doors for people and a baggage door at the back of the car. Something like this:
http://www.tuningnews.net/news/080123a/ ... oor-01.jpg
Re: Is PHP code interpreted or compiled ?
Posted: Tue Feb 23, 2010 9:36 am
by AbraCadaver
Ahhh, a hatchback

Re: Is PHP code interpreted or compiled ?
Posted: Tue Feb 23, 2010 11:27 am
by Jenk
Weirdan wrote:Jenk wrote:No, I'm not saying there are no 20 door cars, I'm saying my type of car is not a 20 door car, even after I have modified it to have 20 doors. It's still a 3 door car, and is marketed as such.
To make it clear I was drawing the analogy between transportation devices and languages. Helicopter (C++) is still a helicopter, regardless of whether it's from Sikorski or Kaman or some other manufacturer. Car (PHP) is a car, regardless of whether it's Fiat or Maserati and whether your particular car has spoilers (extensions) installed.
Jenk wrote:If you download PHP from PHP.net
And what if you download PHP from roadsend.com ?
We can abstract all we like.. so how about this then, PHP as developed and maintained by the PHP Team, is an interpreted language. Other, 3rd party, modifications allow it to be a compiled language, but PHP as it is off the shelf, is interpreted.
And even if we were to have opcaching as default.. that's merely a cache, it is not "compilation" like it is with C, C#, etc. etc. etc. You don't deploy source code in those languages. You do deploy source code with PHP, and providing you have the necessary plugins, they can be cached.
Re: Is PHP code interpreted or compiled ?
Posted: Tue Feb 23, 2010 2:07 pm
by alex.barylski
^^^ Are you a spambot or are you for real serious?
In any case, I would agree that PHP out of the box, when downloaded from PHP.net is an interpreted language, but it can be compiled, as any language could. Caching is similar to compiling, perhaps with the distinction that compiling usually takes several binary objects and brings them under a single roof for easy distribution and execution.
I think when PHP scripts are cached, they are still independent script files which are dynamically included, etc. Not sure how a compiler would deal with this issue, but I assume it requires includes to be static, whereas a opcode cache would simply resolve the dependency on the fly.
Cheers,
Alex