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

josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Is PHP code interpreted or compiled ?

Post by josh »

Not all C++ compilers all support all of the possible features of the C++ language, but they are still considered compilers anyways. Likewise I would say a PHP compiler need not support every PHP language feature. I agree that PHP is "mostly" interpreted, but it is also "somewhat" compiled by any definition :-)
some would argue it was hardly "designed"
pleeeasseee... give me a break. Biased much?
M2tM
Forum Commoner
Posts: 41
Joined: Sat Feb 27, 2010 12:35 pm

Re: Is PHP code interpreted or compiled ?

Post by M2tM »

josh wrote:Not all C++ compilers all support all of the possible features of the C++ language, but they are still considered compilers anyways. Likewise I would say a PHP compiler need not support every PHP language feature. I agree that PHP is "mostly" interpreted, but it is also "somewhat" compiled by any definition :-)
some would argue it was hardly "designed"
pleeeasseee... give me a break. Biased much?
I was pretty clear on how it is "somewhat" compiled. I stated as much explicitly and my explanation pretty much matches exactly what you are saying about it. No argument here. ;) The line is a bit blurry to be sure, but the language itself is generally accepted to be an interpreted language in every reference to it I've seen. Just remember that interpreted languages are commonly "compiled" into an intermediate step and that doesn't make them any less interpreted so long as the thing isn't running on the hardware directly.

Typically this intermediate step is a result of a lexer doing its thing before actual execution of the statements. The fact that you can store the results of the lexer means that you don't have to re-parse the PHP rawcode, but that's hardly executing a compiled language, it's just one step in the interpreter. Lexical analysis is done on every programming language in some form (compiled or interpreted), sometimes it is tied directly to execution, often it is a separate step.
http://en.wikipedia.org/wiki/Lexical_analysis

Again, I don't think we're really -disagreeing- exactly, but I'm not 100% sure.

___

I'm not biased, this is a pretty informed statement based primarily on the organic being which is modern PHP. We have what is essentially a toolkit language with relatively little in the way of standardization. Riddle me this, would a language which had been rigorously designed include in their core the functions:
mysql_escape_string... And then later a function to replace it mysql_real_escape_string. Come on.

How about our good friend magic_quotes which introduces more difficulty than it ever solved?

I'm not even going to bother mentioning the underscore and camel-case inconsistencies or the headache that is trying to work with unicode in PHP.

Objects were added in version 4 and then completely re-done in version 5... Get it right the first time and I might not say it was hardly designed at all. Much of the problem of PHP simply stems from the fact that the language started out as a very basic website template parsing tool and then quickly out-grew that with multiple contributors providing inconsistent language features (many of which are depreciated) and very little direction. The "add it now and ask questions later" mentality is the complete antithesis for "well designed".

The language may be useful, it may be widely distributed and easily accessible. Well-designed it is not. It is getting better, certainly... I am excited and hope that PHP 6 clears up a lot of these issues, but the proof is in the pudding and I am talking about the here and now... Some of these issues strike me especially hard as I support both PHP 4 and PHP 5 because I'm developing tools which I want to be as portable as possible and have no control over the environment.

I've been programming in the language professionally for about 3 years and I know C++ and Javascript pretty well too, you can see and review a project of mine in the code review section to verify that I'm not a (complete) idiot. (*PLUG: while I'm at it, comments and critique would be appreciated on my project: viewtopic.php?f=50&t=113476 . You seem like a very capable programmer and I would relish your feedback!) You seem to do a lot of work with the language too, so I hope you can see some of my points here and recognize that I'm not in this for an argument, and I'm not trying to be controversial.

Despite a little harping on the language I think PHP is a solid choice for web development and I've sunk a significant amount of time into it.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Is PHP code interpreted or compiled ?

Post by josh »

Design != Perfection. PHP does do design, for one there is a community feedback process before any decision is made. These RFCs are done in full public view so I don't know how you can sit there and deny it

Here is a link - http://wiki.php.net/rfc , if this is not design, I must know what is.
M2tM
Forum Commoner
Posts: 41
Joined: Sat Feb 27, 2010 12:35 pm

Re: Is PHP code interpreted or compiled ?

Post by M2tM »

josh wrote:Design != Perfection. PHP does do design, for one there is a community feedback process before any decision is made. These RFCs are done in full public view so I don't know how you can sit there and deny it

Here is a link - http://wiki.php.net/rfc , if this is not design, I must know what is.
Well, let me explain further then. I typically consider design a conscious and focused effort backed with consideration of alternatives before implementation. To me, it seems PHP has mostly lacked this in the past and is, as I said, making improvements in recent versions.

I'm not going to suggest there has been -no- design work done on PHP, I'm not going to pretend I sit in on such meetings. Clearly PHP is a project which is largely popular and has many contributors at this point. But it doesn't take a lot of effort to look at the number of wrong turns implemented in the language to realize that it is, or at least was a pretty loosely designed system.

I don't know how you can work with the language with the degree of proficiency you seem to have and disagree with me on this point. I mean, look at any of the points I brought up and tell me that a well thought-out system would have made those errors before they reached implementation. Point out one other popular language which appears as ad-hock as PHP.

The very fact that it began as a small hobby project and ballooned into what it is today is vindication of my point.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Is PHP code interpreted or compiled ?

Post by josh »

M2tM wrote: But it doesn't take a lot of effort to look at the number of wrong turns implemented in the language to realize that it is, or at least was a pretty loosely designed system.
Well my response would be the same, design != perfection. Back-tracking on design decisions is a sign that lots of iterative design is taking place. Thats desirable (sort of).
I don't know how you can work with the language with the degree of proficiency you seem to have and disagree with me on this point. I mean, look at any of the points I brought up and tell me that a well thought-out system would have made those errors before they reached implementation. .
The problem with that is it is subjective. PHP has "backwards" haystack/needle. Every language is going to have some odd "features" or things you disagree with.

I guess when you get to a certain "degree of proficiency" you learn to work with these features, instead of letting them work against you. Gravity can kill you if you walk off a cliff, but its a desirable property to me, because it keeps me from floating out in space.

Likewise some of the features one person might consider a glitch actually allow for more elegant code if fully understood. But again, its all subjective.

The point we disagree on about if PHP is compiled or interpreted language, is that I think the classification is pointless. We both agree that within the definition posted PHP is interpreted. All I was saying is that I think the definition is pointless. The "whos implementations are mostly" immediately makes it subjective. There are about 5 PHP "compilers". There is about the same # of "interpreters". Which one is "most used"? Answer - its subjective.

Do we measure "most used" by CPU hours? CPUs installed on? Domain names used for? Unique web users to the application? Dollars of revenue generated by the companies using the language? There are too many measures of "most used" for the categorization of compiled vs interpreted to be of any meaning. My viewpoint (which I stated before) is that the classification is meaningless because the definition is subjective (and pointless).
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 »

So now were debating whether PHP was 'designed' over adhoc development? :P

I side with the latter, personally. The language is graceful in many 'off the start' ways, but quickly falls apart in terms of consistency, which is a direct result of planning and design.

PHP is also, primarily used as an interpreted language, much as it is used under the context of Apache not the CLI, it's an incredibly flexible language in ways others have not followed, either by choice or accident.

Arguing over the exact definition of compiling VS interpretation is futile, IMO. There is no one 'right' definition, unless I suppose, you are the original founder of the word. Compiling to me, due to past experience in MS and Borland C/C++ has a very specific meaning, whereas if you used other compilers (such as GCC which, as I understand, at one time converted C++ to C then compiled into binary object files) your definition will probably deviate from mine.

If you are going to discuss the differences in PHP we should probably pick a platform. PHP as downloaded from php.net is not a compiled language, it's tokenized, parsed and evaluated every request. When you install caching engines like APC or IonCube, etc...the generate byte code not machine code, is it still compiled or just a binary representation of interpreted code??? Compiled to me, always meant machine specific code, not pcode, byte code, etc.

This conversation could go on forever in many ways, I think someone needs to list the specifics of this discussion for it to be of much more use to anyone, otherwise, were just voicing opinions with no direction, no?

Cheers,
Alex
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Is PHP code interpreted or compiled ?

Post by josh »

I don't think anyone argued over the meaning of the word "compiling". My note was just that "PHP is also, primarily used as an interpreted language" is just a guess (a darn good one, but still a guess). Maybe everyone on my block has 10,000,000 CPUs in their basement running compiled PHP for me? If I don't tell anyone about it, then you can't make that statement with absolute certainty.

Certainly with all the huge corporations that are on the web, there is bound to be lots of stuff going on that we don't get to hear about. For example 90% of facebook's servers, that probably offsets 100s of thousands of personal developers using it an in "interpreted" way. They've been doing that a year and we just found out last week.

If lets say... all the top 500 alexa sites started using HipHop, would your statement still be true that it is "primarily interpreted"? The mental leap I cannot make it how the # of people using a language change some "underlying property" about that language that is useful for classification in any practical way.

Ps I thought PCspectra knew the difference between "design" and "upfront design".
Post Reply