Is PHP code interpreted or compiled ?

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Re: Is PHP code interpreted or compiled ?

Post 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? :?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Is PHP code interpreted or compiled ?

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Is PHP code interpreted or compiled ?

Post 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.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Re: Is PHP code interpreted or compiled ?

Post 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..
Last edited by Jenk on Tue Feb 23, 2010 3:40 am, edited 1 time in total.
User avatar
timWebUK
Forum Contributor
Posts: 239
Joined: Thu Oct 29, 2009 6:48 am
Location: UK

Re: Is PHP code interpreted or compiled ?

Post 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
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Is PHP code interpreted or compiled ?

Post 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.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Re: Is PHP code interpreted or compiled ?

Post 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".
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Is PHP code interpreted or compiled ?

Post 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.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Re: Is PHP code interpreted or compiled ?

Post 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.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Is PHP code interpreted or compiled ?

Post 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 ?
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Is PHP code interpreted or compiled ?

Post 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?
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Is PHP code interpreted or compiled ?

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Is PHP code interpreted or compiled ?

Post by AbraCadaver »

Weirdan wrote:
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
Ahhh, a hatchback :-)
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Re: Is PHP code interpreted or compiled ?

Post 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.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Is PHP code interpreted or compiled ?

Post 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
Post Reply