Is PHP compiled or interpreted?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
Is PHP compiled or interpreted?
php
add a comment |
Is PHP compiled or interpreted?
php
add a comment |
Is PHP compiled or interpreted?
php
Is PHP compiled or interpreted?
php
php
edited Dec 17 '10 at 19:03


Peter Mortensen
13.9k1987114
13.9k1987114
asked Oct 3 '09 at 19:56
nickynicky
1,90562939
1,90562939
add a comment |
add a comment |
14 Answers
14
active
oldest
votes
The PHP language is interpreted. The binary that lets you interpret PHP is compiled, but what you write is interpreted.
You can see more on the wikipedia page for Interpreted languages
22
He means the utility called php (or on windows php.exe) is compiled.
– sepp2k
Oct 3 '09 at 20:02
6
@nicky It means that the program that's used to interpret PHP is compiled, but the PHP itself is interpreted.
– Andrew Song
Oct 3 '09 at 20:03
5
But why its mentioned like this in wikipedia? goo.gl/YOwZ Since PHP 4, the PHP parser compiles input to produce bytecode for processing by the Zend Engine, giving improved performance over its interpreter predecessor.
– kiranvj
Jul 28 '12 at 16:17
5
@kiranvj It is indeed compiled for improved performances, but at runtime. Think of "compiled languages" as "pre-compiled", and interpreted languages as "Compiled when run". It's the difference between these two: - JIT ("Just in time"), where only the code that is needed is compiled when it's needed (note, however, that after the interpreter quits, the compiled code is lot) - AOT ("Ahead of time"), where the all the code is compiled before it is run.
– Thibault Martin-Lagardette
Oct 16 '12 at 9:37
3
@kiranvj: I believe OP wanted to know if PHP gets compiled to the native code. Compiling it to bytecode, which is then again interpreted by Zend, is somewhere in the middle in terms of compilation cost and runtime performance. Lol, this is a rather old thread, just realized it.
– Groo
Dec 10 '12 at 18:16
|
show 3 more comments
Both. PHP is compiled down to an intermediate bytecode that is then interpreted by the runtime engine.
The PHP compiler's job is to parse your PHP code and convert it into a form suitable for the runtime engine. Among its tasks:
- Ignore comments
- Resolve variables, function names, and so forth and create the symbol table
- Construct the abstract syntax tree of your program
- Write the bytecode
Depending on your PHP setup, this step is typically done just once, the first time the script is called. The compiler output is cached to speed up access on subsequent uses. If the script is modified, however, the compilation step is done again.
The runtime engine walks the AST and bytecode when the script is called. The symbol table is used to store the values of variables and provide the bytecode addresses for functions.
This process of compiling to bytecode and interpreting it at runtime is typical for languages that run on some kind of virtual runtime machine including Perl, Java, Ruby, Smalltalk, and others.
Variable binding happens at runtime, not compile time.
– jrockway
Oct 4 '09 at 0:30
PHP doesn't even attempt to resolve which names are in scope at compile time?
– Barry Brown
Oct 4 '09 at 1:04
Helpful diagram: bayanbox.ir/view/8066466214302126886/php-internals.jpg
– Yousha Aleayoub
Mar 5 at 11:49
add a comment |
In generally it is interpreted, but some time can use it as compiled and it is really increases performance.
Open source tool to perform this operation:
hhvm.com
6
May I also add hhvm.com
– JohnnyQ
Jun 25 '14 at 2:29
add a comment |
PHP is an interpreted language. It can be compiled to bytecode by third party-tools, though.
1
"bytecode" is a term used for VM specific pseudo instructions, which are not native hence can't be regarded as "compilation" in this context.
– Sedat Kapanoglu
Oct 3 '09 at 20:12
4
"object code" is just bytecode for the CPU's instruction decoder. (You don't think that CPUs actually have native instructions like "CMPSB", right?)
– jrockway
Oct 3 '09 at 20:58
add a comment |
A compiled code can be executed directly by the computer's CPU. That is, the executable code is specified in the CPU's native language
The code of interpreted languages must be translated at run-time from any format to CPU machine instructions. This translation is done by an interpreter.
It would not be proper to say that a language is interpreted or compiled because interpretation and compilation are both properties of the implementation of that particular language, and not a property of the language itself. So,any language can be compiled or interpreted – it just depends on what the particular implementation that you are using does.
The most widely used PHP implementation is powered by the Zend Engine and known simply as PHP.The Zend Engine compiles PHP source into a format that it can execute, thus the Zend engine works as an interpreter.
Thankyou :)
2
"That is, the executable code is specified in the CPU's native language" .. Executable code is not specified in CPU's native language but in binary format, CPU's native language could be anything and when software binaries doesn't come like it is for this CPU or that CPU .. A fully compiled and executable code will be in binary format ..
– hagrawal
Apr 10 '16 at 2:44
add a comment |
This is a meaningless question. PHP uses yacc (bison), just like GCC. yacc is a "compiler compiler". The output of yacc is a compiler. The output of a compiler is "compiled". PHP is parsed by the output of yacc. So it is, by definition, compiled.
If that doesn't satisfy, consider the following. Both php (the binary) and gcc read your source code and produce an abstract syntax tree. Under versions 4 and 5, php then walks the tree to translate the program to bytecode (the compilation step). You can see the bytecode translated to opcodes (which are analogous to assembly) using the Vulcan Logic Dumper. Finally, php (in particular, the Zend engine) interprets the bytecode. gcc, in comparison, walks the tree and outputs assembly; it can also run assemblers and linkers to finish the process. Calling a program handled by one "interpreted" and another program handled by the other "compiled" is meaningless. After all, programs are both run through a "compiler" with both.
You should actually ask the question you want to ask instead. ("Do I pay a performance penalty as PHP recompiles my source code for every request?", etc.)
4
Tokenizing a source code is not compiling. Even VBScript can be regarded as a compiled language with your definition.
– Sedat Kapanoglu
Oct 3 '09 at 20:13
3
I'm with jrockway on this, although it doesn't really answer the OP's question. It's tempting to create a taxonomy of languages in which every language is placed cleanly into each category. But the reality isn't so neat. Almost every language is a blend of characteristics. Plus, when you get right down to it, even native machine code is "interpreted" by the processor.
– Barry Brown
Oct 3 '09 at 22:33
4
Your high level assertion is correct, this is a meaningless question. Your argument however isn't very helpful, all you've done is taken fuzzy definitions and taken them to extremes. Compilation is the transformation of source into object code. Yes you can consider the transformation of source into a concrete/abstract syntax tree a compilation, but that's not what most people mean is it? Regardless, this is a meaningless question because a language is not INHERENTLY compiled or interpreted, implmentations of a language are compiled or interpreted.
– Falaina
Oct 3 '09 at 23:25
4
let's not oversee that the guy is a beginner. this makes me interpret the question as "does Zend implementation produce native code out of PHP source?". check out my answer. i think you're being too strict about the way the question is asked. you know, we're trying to help, not bash some newbies.
– Sedat Kapanoglu
Oct 4 '09 at 7:27
1
I got to this question from 'does php compile to bytecode' in which case I think the difference is relevant.
– xenoterracide
May 31 '12 at 2:32
|
show 3 more comments
I know this question is old but it's linked all over the place and I think all answers here are incorrect (maybe because they're old).
There is NO such thing as an interpreted language or a compiled language. Any programming language can be interpreted and/or compiled.
First of all a language is just a set of rules, so when we are talking about compilation we refer to specific implementations of that language.
HHVM, for example, is an implementation of PHP. It uses JIT compilation to transform the code to intermediate HipHop bytecode and then translated into machine code. Is it enough to say it is compiled? Some Java implementations (not all) also use JIT. Google's V8 also uses JIT.
Using the old definitions of compiled vs. interpreted does not make sense nowadays.
"Is PHP compiled?" is a non-sensical question given that there are no
longer clear and agreed delimiters between what is a compiled language vs an
interpreted one.
One possible way to delimit them is (I don't find any meaning in this dichotomy):
compiled languages use Ahead of Time compilation (C, C++);
interpreted languages use Just in Time compilation or no compilation at all (Python, Ruby, PHP, Java).
Doesn't Java use ahead of time compilation in most cases, though? I'm a fairly new Java developer and we usually compile our code way before runtime.
– aCarella
Oct 30 '17 at 12:37
@aCarellain most cases
, yes. in all cases, no. so you cannot draw a line that is semantically significant and agreed.
– Claudiu Creanga
Oct 30 '17 at 14:43
add a comment |
At least it doesn't compile (or should I say optimize) the code as much as one might want it.
This code...
for($i=0;$i<100000000;$i++);
echo $i;
...delays the program equally much each time it is run.
It could have detected that it is a calculation that only needs to be done the first time.
Now we have a option called generators.
– Ankit Vishwakarma
Feb 5 '16 at 18:56
add a comment |
PHP is an interpreted language but the program used to interpret PHP is complied.
PHP compiler generates the bytecode which is machine independents later this bytecode converts into machine understandable code by run time engine.
add a comment |
Its interpreted. So keep that in mind when you put too many comments in your code...
1
This answer would have been true for BASIC.
– Barry Brown
Oct 3 '09 at 20:19
1
Why -3? This answer is true, even for php. The analyzation of whether an instruction is a comment just takes an unsignificant amount of time.
– Atmocreations
Oct 3 '09 at 21:24
You take the hit only the first time your script is used.
– Barry Brown
Oct 3 '09 at 23:20
3
I've never looked at code and thought "if only it used fewer comments, then all our performance problems would go away!" And neither have you.
– JohnFF
Jul 3 '17 at 12:45
1
@Dheeraj: I wasn't talking about small to moderate number of comments. I'm talking about not including your entire doc as pure comments in your code. All of you are freaking out like I'm saying "NEVER PUT COMMENTS IN YOUR CODE HUR HUR HUR.". No. That's not what I said. If you do actually put hundreds of thousands of lines of comments in your small PHP application, then perhaps you do need a better documentation system, and write more readable code while you're at it.
– Stanislav Palatnik
Aug 6 '17 at 17:39
|
show 2 more comments
Traditional categorization of compilers and interpreters is blurry in case of just-in-time compilation and bytecode interpretation.PHP is interpreted.But,that does not mean that PHP is not compiled.PHP compiler perform syntax checking,intermediate code generation and optimization.PHP is interpreted because object code that PHP compiler generates is parsed by another precompiled native binary.Which interprets intermediate code to cpu readable instruction.Thats why no other language can be as first as assembly language in term of instruction execution.Because, instructions a assembler( assembly compiler) produce are already there in cpu.
add a comment |
It is interpreted as PHP code is interpreted by an engine(commonly converted into bytecode first); it is also compiled as some tools can compile PHP code into the an executable, like phc.
add a comment |
Obviously php.exe
(the PHP interpreter) is a compiled executable.
However, I don't think that's what you asked.
When a PHP script is loaded, it get's compiled into a binary format known as Zend opcodes, into the memory, which are then interpreted efficiently.
Source: https://stackoverflow.com/a/18595821/3881189
add a comment |
php is Interpreter, You don't compile it, you save it in file and server reads it line by line. C++ is compiled, you compile the whole script and then run the exe, your program. Too late to make changes now.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f1514676%2fis-php-compiled-or-interpreted%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
14 Answers
14
active
oldest
votes
14 Answers
14
active
oldest
votes
active
oldest
votes
active
oldest
votes
The PHP language is interpreted. The binary that lets you interpret PHP is compiled, but what you write is interpreted.
You can see more on the wikipedia page for Interpreted languages
22
He means the utility called php (or on windows php.exe) is compiled.
– sepp2k
Oct 3 '09 at 20:02
6
@nicky It means that the program that's used to interpret PHP is compiled, but the PHP itself is interpreted.
– Andrew Song
Oct 3 '09 at 20:03
5
But why its mentioned like this in wikipedia? goo.gl/YOwZ Since PHP 4, the PHP parser compiles input to produce bytecode for processing by the Zend Engine, giving improved performance over its interpreter predecessor.
– kiranvj
Jul 28 '12 at 16:17
5
@kiranvj It is indeed compiled for improved performances, but at runtime. Think of "compiled languages" as "pre-compiled", and interpreted languages as "Compiled when run". It's the difference between these two: - JIT ("Just in time"), where only the code that is needed is compiled when it's needed (note, however, that after the interpreter quits, the compiled code is lot) - AOT ("Ahead of time"), where the all the code is compiled before it is run.
– Thibault Martin-Lagardette
Oct 16 '12 at 9:37
3
@kiranvj: I believe OP wanted to know if PHP gets compiled to the native code. Compiling it to bytecode, which is then again interpreted by Zend, is somewhere in the middle in terms of compilation cost and runtime performance. Lol, this is a rather old thread, just realized it.
– Groo
Dec 10 '12 at 18:16
|
show 3 more comments
The PHP language is interpreted. The binary that lets you interpret PHP is compiled, but what you write is interpreted.
You can see more on the wikipedia page for Interpreted languages
22
He means the utility called php (or on windows php.exe) is compiled.
– sepp2k
Oct 3 '09 at 20:02
6
@nicky It means that the program that's used to interpret PHP is compiled, but the PHP itself is interpreted.
– Andrew Song
Oct 3 '09 at 20:03
5
But why its mentioned like this in wikipedia? goo.gl/YOwZ Since PHP 4, the PHP parser compiles input to produce bytecode for processing by the Zend Engine, giving improved performance over its interpreter predecessor.
– kiranvj
Jul 28 '12 at 16:17
5
@kiranvj It is indeed compiled for improved performances, but at runtime. Think of "compiled languages" as "pre-compiled", and interpreted languages as "Compiled when run". It's the difference between these two: - JIT ("Just in time"), where only the code that is needed is compiled when it's needed (note, however, that after the interpreter quits, the compiled code is lot) - AOT ("Ahead of time"), where the all the code is compiled before it is run.
– Thibault Martin-Lagardette
Oct 16 '12 at 9:37
3
@kiranvj: I believe OP wanted to know if PHP gets compiled to the native code. Compiling it to bytecode, which is then again interpreted by Zend, is somewhere in the middle in terms of compilation cost and runtime performance. Lol, this is a rather old thread, just realized it.
– Groo
Dec 10 '12 at 18:16
|
show 3 more comments
The PHP language is interpreted. The binary that lets you interpret PHP is compiled, but what you write is interpreted.
You can see more on the wikipedia page for Interpreted languages
The PHP language is interpreted. The binary that lets you interpret PHP is compiled, but what you write is interpreted.
You can see more on the wikipedia page for Interpreted languages
edited Oct 3 '09 at 22:54
Jim Ferrans
22k104880
22k104880
answered Oct 3 '09 at 19:57
Thibault Martin-LagardetteThibault Martin-Lagardette
3,96431818
3,96431818
22
He means the utility called php (or on windows php.exe) is compiled.
– sepp2k
Oct 3 '09 at 20:02
6
@nicky It means that the program that's used to interpret PHP is compiled, but the PHP itself is interpreted.
– Andrew Song
Oct 3 '09 at 20:03
5
But why its mentioned like this in wikipedia? goo.gl/YOwZ Since PHP 4, the PHP parser compiles input to produce bytecode for processing by the Zend Engine, giving improved performance over its interpreter predecessor.
– kiranvj
Jul 28 '12 at 16:17
5
@kiranvj It is indeed compiled for improved performances, but at runtime. Think of "compiled languages" as "pre-compiled", and interpreted languages as "Compiled when run". It's the difference between these two: - JIT ("Just in time"), where only the code that is needed is compiled when it's needed (note, however, that after the interpreter quits, the compiled code is lot) - AOT ("Ahead of time"), where the all the code is compiled before it is run.
– Thibault Martin-Lagardette
Oct 16 '12 at 9:37
3
@kiranvj: I believe OP wanted to know if PHP gets compiled to the native code. Compiling it to bytecode, which is then again interpreted by Zend, is somewhere in the middle in terms of compilation cost and runtime performance. Lol, this is a rather old thread, just realized it.
– Groo
Dec 10 '12 at 18:16
|
show 3 more comments
22
He means the utility called php (or on windows php.exe) is compiled.
– sepp2k
Oct 3 '09 at 20:02
6
@nicky It means that the program that's used to interpret PHP is compiled, but the PHP itself is interpreted.
– Andrew Song
Oct 3 '09 at 20:03
5
But why its mentioned like this in wikipedia? goo.gl/YOwZ Since PHP 4, the PHP parser compiles input to produce bytecode for processing by the Zend Engine, giving improved performance over its interpreter predecessor.
– kiranvj
Jul 28 '12 at 16:17
5
@kiranvj It is indeed compiled for improved performances, but at runtime. Think of "compiled languages" as "pre-compiled", and interpreted languages as "Compiled when run". It's the difference between these two: - JIT ("Just in time"), where only the code that is needed is compiled when it's needed (note, however, that after the interpreter quits, the compiled code is lot) - AOT ("Ahead of time"), where the all the code is compiled before it is run.
– Thibault Martin-Lagardette
Oct 16 '12 at 9:37
3
@kiranvj: I believe OP wanted to know if PHP gets compiled to the native code. Compiling it to bytecode, which is then again interpreted by Zend, is somewhere in the middle in terms of compilation cost and runtime performance. Lol, this is a rather old thread, just realized it.
– Groo
Dec 10 '12 at 18:16
22
22
He means the utility called php (or on windows php.exe) is compiled.
– sepp2k
Oct 3 '09 at 20:02
He means the utility called php (or on windows php.exe) is compiled.
– sepp2k
Oct 3 '09 at 20:02
6
6
@nicky It means that the program that's used to interpret PHP is compiled, but the PHP itself is interpreted.
– Andrew Song
Oct 3 '09 at 20:03
@nicky It means that the program that's used to interpret PHP is compiled, but the PHP itself is interpreted.
– Andrew Song
Oct 3 '09 at 20:03
5
5
But why its mentioned like this in wikipedia? goo.gl/YOwZ Since PHP 4, the PHP parser compiles input to produce bytecode for processing by the Zend Engine, giving improved performance over its interpreter predecessor.
– kiranvj
Jul 28 '12 at 16:17
But why its mentioned like this in wikipedia? goo.gl/YOwZ Since PHP 4, the PHP parser compiles input to produce bytecode for processing by the Zend Engine, giving improved performance over its interpreter predecessor.
– kiranvj
Jul 28 '12 at 16:17
5
5
@kiranvj It is indeed compiled for improved performances, but at runtime. Think of "compiled languages" as "pre-compiled", and interpreted languages as "Compiled when run". It's the difference between these two: - JIT ("Just in time"), where only the code that is needed is compiled when it's needed (note, however, that after the interpreter quits, the compiled code is lot) - AOT ("Ahead of time"), where the all the code is compiled before it is run.
– Thibault Martin-Lagardette
Oct 16 '12 at 9:37
@kiranvj It is indeed compiled for improved performances, but at runtime. Think of "compiled languages" as "pre-compiled", and interpreted languages as "Compiled when run". It's the difference between these two: - JIT ("Just in time"), where only the code that is needed is compiled when it's needed (note, however, that after the interpreter quits, the compiled code is lot) - AOT ("Ahead of time"), where the all the code is compiled before it is run.
– Thibault Martin-Lagardette
Oct 16 '12 at 9:37
3
3
@kiranvj: I believe OP wanted to know if PHP gets compiled to the native code. Compiling it to bytecode, which is then again interpreted by Zend, is somewhere in the middle in terms of compilation cost and runtime performance. Lol, this is a rather old thread, just realized it.
– Groo
Dec 10 '12 at 18:16
@kiranvj: I believe OP wanted to know if PHP gets compiled to the native code. Compiling it to bytecode, which is then again interpreted by Zend, is somewhere in the middle in terms of compilation cost and runtime performance. Lol, this is a rather old thread, just realized it.
– Groo
Dec 10 '12 at 18:16
|
show 3 more comments
Both. PHP is compiled down to an intermediate bytecode that is then interpreted by the runtime engine.
The PHP compiler's job is to parse your PHP code and convert it into a form suitable for the runtime engine. Among its tasks:
- Ignore comments
- Resolve variables, function names, and so forth and create the symbol table
- Construct the abstract syntax tree of your program
- Write the bytecode
Depending on your PHP setup, this step is typically done just once, the first time the script is called. The compiler output is cached to speed up access on subsequent uses. If the script is modified, however, the compilation step is done again.
The runtime engine walks the AST and bytecode when the script is called. The symbol table is used to store the values of variables and provide the bytecode addresses for functions.
This process of compiling to bytecode and interpreting it at runtime is typical for languages that run on some kind of virtual runtime machine including Perl, Java, Ruby, Smalltalk, and others.
Variable binding happens at runtime, not compile time.
– jrockway
Oct 4 '09 at 0:30
PHP doesn't even attempt to resolve which names are in scope at compile time?
– Barry Brown
Oct 4 '09 at 1:04
Helpful diagram: bayanbox.ir/view/8066466214302126886/php-internals.jpg
– Yousha Aleayoub
Mar 5 at 11:49
add a comment |
Both. PHP is compiled down to an intermediate bytecode that is then interpreted by the runtime engine.
The PHP compiler's job is to parse your PHP code and convert it into a form suitable for the runtime engine. Among its tasks:
- Ignore comments
- Resolve variables, function names, and so forth and create the symbol table
- Construct the abstract syntax tree of your program
- Write the bytecode
Depending on your PHP setup, this step is typically done just once, the first time the script is called. The compiler output is cached to speed up access on subsequent uses. If the script is modified, however, the compilation step is done again.
The runtime engine walks the AST and bytecode when the script is called. The symbol table is used to store the values of variables and provide the bytecode addresses for functions.
This process of compiling to bytecode and interpreting it at runtime is typical for languages that run on some kind of virtual runtime machine including Perl, Java, Ruby, Smalltalk, and others.
Variable binding happens at runtime, not compile time.
– jrockway
Oct 4 '09 at 0:30
PHP doesn't even attempt to resolve which names are in scope at compile time?
– Barry Brown
Oct 4 '09 at 1:04
Helpful diagram: bayanbox.ir/view/8066466214302126886/php-internals.jpg
– Yousha Aleayoub
Mar 5 at 11:49
add a comment |
Both. PHP is compiled down to an intermediate bytecode that is then interpreted by the runtime engine.
The PHP compiler's job is to parse your PHP code and convert it into a form suitable for the runtime engine. Among its tasks:
- Ignore comments
- Resolve variables, function names, and so forth and create the symbol table
- Construct the abstract syntax tree of your program
- Write the bytecode
Depending on your PHP setup, this step is typically done just once, the first time the script is called. The compiler output is cached to speed up access on subsequent uses. If the script is modified, however, the compilation step is done again.
The runtime engine walks the AST and bytecode when the script is called. The symbol table is used to store the values of variables and provide the bytecode addresses for functions.
This process of compiling to bytecode and interpreting it at runtime is typical for languages that run on some kind of virtual runtime machine including Perl, Java, Ruby, Smalltalk, and others.
Both. PHP is compiled down to an intermediate bytecode that is then interpreted by the runtime engine.
The PHP compiler's job is to parse your PHP code and convert it into a form suitable for the runtime engine. Among its tasks:
- Ignore comments
- Resolve variables, function names, and so forth and create the symbol table
- Construct the abstract syntax tree of your program
- Write the bytecode
Depending on your PHP setup, this step is typically done just once, the first time the script is called. The compiler output is cached to speed up access on subsequent uses. If the script is modified, however, the compilation step is done again.
The runtime engine walks the AST and bytecode when the script is called. The symbol table is used to store the values of variables and provide the bytecode addresses for functions.
This process of compiling to bytecode and interpreting it at runtime is typical for languages that run on some kind of virtual runtime machine including Perl, Java, Ruby, Smalltalk, and others.
answered Oct 3 '09 at 20:18
Barry BrownBarry Brown
13.5k116098
13.5k116098
Variable binding happens at runtime, not compile time.
– jrockway
Oct 4 '09 at 0:30
PHP doesn't even attempt to resolve which names are in scope at compile time?
– Barry Brown
Oct 4 '09 at 1:04
Helpful diagram: bayanbox.ir/view/8066466214302126886/php-internals.jpg
– Yousha Aleayoub
Mar 5 at 11:49
add a comment |
Variable binding happens at runtime, not compile time.
– jrockway
Oct 4 '09 at 0:30
PHP doesn't even attempt to resolve which names are in scope at compile time?
– Barry Brown
Oct 4 '09 at 1:04
Helpful diagram: bayanbox.ir/view/8066466214302126886/php-internals.jpg
– Yousha Aleayoub
Mar 5 at 11:49
Variable binding happens at runtime, not compile time.
– jrockway
Oct 4 '09 at 0:30
Variable binding happens at runtime, not compile time.
– jrockway
Oct 4 '09 at 0:30
PHP doesn't even attempt to resolve which names are in scope at compile time?
– Barry Brown
Oct 4 '09 at 1:04
PHP doesn't even attempt to resolve which names are in scope at compile time?
– Barry Brown
Oct 4 '09 at 1:04
Helpful diagram: bayanbox.ir/view/8066466214302126886/php-internals.jpg
– Yousha Aleayoub
Mar 5 at 11:49
Helpful diagram: bayanbox.ir/view/8066466214302126886/php-internals.jpg
– Yousha Aleayoub
Mar 5 at 11:49
add a comment |
In generally it is interpreted, but some time can use it as compiled and it is really increases performance.
Open source tool to perform this operation:
hhvm.com
6
May I also add hhvm.com
– JohnnyQ
Jun 25 '14 at 2:29
add a comment |
In generally it is interpreted, but some time can use it as compiled and it is really increases performance.
Open source tool to perform this operation:
hhvm.com
6
May I also add hhvm.com
– JohnnyQ
Jun 25 '14 at 2:29
add a comment |
In generally it is interpreted, but some time can use it as compiled and it is really increases performance.
Open source tool to perform this operation:
hhvm.com
In generally it is interpreted, but some time can use it as compiled and it is really increases performance.
Open source tool to perform this operation:
hhvm.com
edited Jan 3 at 15:18


Dany Caissy
2,928918
2,928918
answered Oct 3 '09 at 20:06
MaxMax
1,31242548
1,31242548
6
May I also add hhvm.com
– JohnnyQ
Jun 25 '14 at 2:29
add a comment |
6
May I also add hhvm.com
– JohnnyQ
Jun 25 '14 at 2:29
6
6
May I also add hhvm.com
– JohnnyQ
Jun 25 '14 at 2:29
May I also add hhvm.com
– JohnnyQ
Jun 25 '14 at 2:29
add a comment |
PHP is an interpreted language. It can be compiled to bytecode by third party-tools, though.
1
"bytecode" is a term used for VM specific pseudo instructions, which are not native hence can't be regarded as "compilation" in this context.
– Sedat Kapanoglu
Oct 3 '09 at 20:12
4
"object code" is just bytecode for the CPU's instruction decoder. (You don't think that CPUs actually have native instructions like "CMPSB", right?)
– jrockway
Oct 3 '09 at 20:58
add a comment |
PHP is an interpreted language. It can be compiled to bytecode by third party-tools, though.
1
"bytecode" is a term used for VM specific pseudo instructions, which are not native hence can't be regarded as "compilation" in this context.
– Sedat Kapanoglu
Oct 3 '09 at 20:12
4
"object code" is just bytecode for the CPU's instruction decoder. (You don't think that CPUs actually have native instructions like "CMPSB", right?)
– jrockway
Oct 3 '09 at 20:58
add a comment |
PHP is an interpreted language. It can be compiled to bytecode by third party-tools, though.
PHP is an interpreted language. It can be compiled to bytecode by third party-tools, though.
edited Mar 22 '12 at 12:20
answered Oct 3 '09 at 19:58
code_burgarcode_burgar
9,53042751
9,53042751
1
"bytecode" is a term used for VM specific pseudo instructions, which are not native hence can't be regarded as "compilation" in this context.
– Sedat Kapanoglu
Oct 3 '09 at 20:12
4
"object code" is just bytecode for the CPU's instruction decoder. (You don't think that CPUs actually have native instructions like "CMPSB", right?)
– jrockway
Oct 3 '09 at 20:58
add a comment |
1
"bytecode" is a term used for VM specific pseudo instructions, which are not native hence can't be regarded as "compilation" in this context.
– Sedat Kapanoglu
Oct 3 '09 at 20:12
4
"object code" is just bytecode for the CPU's instruction decoder. (You don't think that CPUs actually have native instructions like "CMPSB", right?)
– jrockway
Oct 3 '09 at 20:58
1
1
"bytecode" is a term used for VM specific pseudo instructions, which are not native hence can't be regarded as "compilation" in this context.
– Sedat Kapanoglu
Oct 3 '09 at 20:12
"bytecode" is a term used for VM specific pseudo instructions, which are not native hence can't be regarded as "compilation" in this context.
– Sedat Kapanoglu
Oct 3 '09 at 20:12
4
4
"object code" is just bytecode for the CPU's instruction decoder. (You don't think that CPUs actually have native instructions like "CMPSB", right?)
– jrockway
Oct 3 '09 at 20:58
"object code" is just bytecode for the CPU's instruction decoder. (You don't think that CPUs actually have native instructions like "CMPSB", right?)
– jrockway
Oct 3 '09 at 20:58
add a comment |
A compiled code can be executed directly by the computer's CPU. That is, the executable code is specified in the CPU's native language
The code of interpreted languages must be translated at run-time from any format to CPU machine instructions. This translation is done by an interpreter.
It would not be proper to say that a language is interpreted or compiled because interpretation and compilation are both properties of the implementation of that particular language, and not a property of the language itself. So,any language can be compiled or interpreted – it just depends on what the particular implementation that you are using does.
The most widely used PHP implementation is powered by the Zend Engine and known simply as PHP.The Zend Engine compiles PHP source into a format that it can execute, thus the Zend engine works as an interpreter.
Thankyou :)
2
"That is, the executable code is specified in the CPU's native language" .. Executable code is not specified in CPU's native language but in binary format, CPU's native language could be anything and when software binaries doesn't come like it is for this CPU or that CPU .. A fully compiled and executable code will be in binary format ..
– hagrawal
Apr 10 '16 at 2:44
add a comment |
A compiled code can be executed directly by the computer's CPU. That is, the executable code is specified in the CPU's native language
The code of interpreted languages must be translated at run-time from any format to CPU machine instructions. This translation is done by an interpreter.
It would not be proper to say that a language is interpreted or compiled because interpretation and compilation are both properties of the implementation of that particular language, and not a property of the language itself. So,any language can be compiled or interpreted – it just depends on what the particular implementation that you are using does.
The most widely used PHP implementation is powered by the Zend Engine and known simply as PHP.The Zend Engine compiles PHP source into a format that it can execute, thus the Zend engine works as an interpreter.
Thankyou :)
2
"That is, the executable code is specified in the CPU's native language" .. Executable code is not specified in CPU's native language but in binary format, CPU's native language could be anything and when software binaries doesn't come like it is for this CPU or that CPU .. A fully compiled and executable code will be in binary format ..
– hagrawal
Apr 10 '16 at 2:44
add a comment |
A compiled code can be executed directly by the computer's CPU. That is, the executable code is specified in the CPU's native language
The code of interpreted languages must be translated at run-time from any format to CPU machine instructions. This translation is done by an interpreter.
It would not be proper to say that a language is interpreted or compiled because interpretation and compilation are both properties of the implementation of that particular language, and not a property of the language itself. So,any language can be compiled or interpreted – it just depends on what the particular implementation that you are using does.
The most widely used PHP implementation is powered by the Zend Engine and known simply as PHP.The Zend Engine compiles PHP source into a format that it can execute, thus the Zend engine works as an interpreter.
Thankyou :)
A compiled code can be executed directly by the computer's CPU. That is, the executable code is specified in the CPU's native language
The code of interpreted languages must be translated at run-time from any format to CPU machine instructions. This translation is done by an interpreter.
It would not be proper to say that a language is interpreted or compiled because interpretation and compilation are both properties of the implementation of that particular language, and not a property of the language itself. So,any language can be compiled or interpreted – it just depends on what the particular implementation that you are using does.
The most widely used PHP implementation is powered by the Zend Engine and known simply as PHP.The Zend Engine compiles PHP source into a format that it can execute, thus the Zend engine works as an interpreter.
Thankyou :)
edited Dec 23 '15 at 14:58
answered Aug 19 '15 at 6:09
Gaurang DeshpandeGaurang Deshpande
478410
478410
2
"That is, the executable code is specified in the CPU's native language" .. Executable code is not specified in CPU's native language but in binary format, CPU's native language could be anything and when software binaries doesn't come like it is for this CPU or that CPU .. A fully compiled and executable code will be in binary format ..
– hagrawal
Apr 10 '16 at 2:44
add a comment |
2
"That is, the executable code is specified in the CPU's native language" .. Executable code is not specified in CPU's native language but in binary format, CPU's native language could be anything and when software binaries doesn't come like it is for this CPU or that CPU .. A fully compiled and executable code will be in binary format ..
– hagrawal
Apr 10 '16 at 2:44
2
2
"That is, the executable code is specified in the CPU's native language" .. Executable code is not specified in CPU's native language but in binary format, CPU's native language could be anything and when software binaries doesn't come like it is for this CPU or that CPU .. A fully compiled and executable code will be in binary format ..
– hagrawal
Apr 10 '16 at 2:44
"That is, the executable code is specified in the CPU's native language" .. Executable code is not specified in CPU's native language but in binary format, CPU's native language could be anything and when software binaries doesn't come like it is for this CPU or that CPU .. A fully compiled and executable code will be in binary format ..
– hagrawal
Apr 10 '16 at 2:44
add a comment |
This is a meaningless question. PHP uses yacc (bison), just like GCC. yacc is a "compiler compiler". The output of yacc is a compiler. The output of a compiler is "compiled". PHP is parsed by the output of yacc. So it is, by definition, compiled.
If that doesn't satisfy, consider the following. Both php (the binary) and gcc read your source code and produce an abstract syntax tree. Under versions 4 and 5, php then walks the tree to translate the program to bytecode (the compilation step). You can see the bytecode translated to opcodes (which are analogous to assembly) using the Vulcan Logic Dumper. Finally, php (in particular, the Zend engine) interprets the bytecode. gcc, in comparison, walks the tree and outputs assembly; it can also run assemblers and linkers to finish the process. Calling a program handled by one "interpreted" and another program handled by the other "compiled" is meaningless. After all, programs are both run through a "compiler" with both.
You should actually ask the question you want to ask instead. ("Do I pay a performance penalty as PHP recompiles my source code for every request?", etc.)
4
Tokenizing a source code is not compiling. Even VBScript can be regarded as a compiled language with your definition.
– Sedat Kapanoglu
Oct 3 '09 at 20:13
3
I'm with jrockway on this, although it doesn't really answer the OP's question. It's tempting to create a taxonomy of languages in which every language is placed cleanly into each category. But the reality isn't so neat. Almost every language is a blend of characteristics. Plus, when you get right down to it, even native machine code is "interpreted" by the processor.
– Barry Brown
Oct 3 '09 at 22:33
4
Your high level assertion is correct, this is a meaningless question. Your argument however isn't very helpful, all you've done is taken fuzzy definitions and taken them to extremes. Compilation is the transformation of source into object code. Yes you can consider the transformation of source into a concrete/abstract syntax tree a compilation, but that's not what most people mean is it? Regardless, this is a meaningless question because a language is not INHERENTLY compiled or interpreted, implmentations of a language are compiled or interpreted.
– Falaina
Oct 3 '09 at 23:25
4
let's not oversee that the guy is a beginner. this makes me interpret the question as "does Zend implementation produce native code out of PHP source?". check out my answer. i think you're being too strict about the way the question is asked. you know, we're trying to help, not bash some newbies.
– Sedat Kapanoglu
Oct 4 '09 at 7:27
1
I got to this question from 'does php compile to bytecode' in which case I think the difference is relevant.
– xenoterracide
May 31 '12 at 2:32
|
show 3 more comments
This is a meaningless question. PHP uses yacc (bison), just like GCC. yacc is a "compiler compiler". The output of yacc is a compiler. The output of a compiler is "compiled". PHP is parsed by the output of yacc. So it is, by definition, compiled.
If that doesn't satisfy, consider the following. Both php (the binary) and gcc read your source code and produce an abstract syntax tree. Under versions 4 and 5, php then walks the tree to translate the program to bytecode (the compilation step). You can see the bytecode translated to opcodes (which are analogous to assembly) using the Vulcan Logic Dumper. Finally, php (in particular, the Zend engine) interprets the bytecode. gcc, in comparison, walks the tree and outputs assembly; it can also run assemblers and linkers to finish the process. Calling a program handled by one "interpreted" and another program handled by the other "compiled" is meaningless. After all, programs are both run through a "compiler" with both.
You should actually ask the question you want to ask instead. ("Do I pay a performance penalty as PHP recompiles my source code for every request?", etc.)
4
Tokenizing a source code is not compiling. Even VBScript can be regarded as a compiled language with your definition.
– Sedat Kapanoglu
Oct 3 '09 at 20:13
3
I'm with jrockway on this, although it doesn't really answer the OP's question. It's tempting to create a taxonomy of languages in which every language is placed cleanly into each category. But the reality isn't so neat. Almost every language is a blend of characteristics. Plus, when you get right down to it, even native machine code is "interpreted" by the processor.
– Barry Brown
Oct 3 '09 at 22:33
4
Your high level assertion is correct, this is a meaningless question. Your argument however isn't very helpful, all you've done is taken fuzzy definitions and taken them to extremes. Compilation is the transformation of source into object code. Yes you can consider the transformation of source into a concrete/abstract syntax tree a compilation, but that's not what most people mean is it? Regardless, this is a meaningless question because a language is not INHERENTLY compiled or interpreted, implmentations of a language are compiled or interpreted.
– Falaina
Oct 3 '09 at 23:25
4
let's not oversee that the guy is a beginner. this makes me interpret the question as "does Zend implementation produce native code out of PHP source?". check out my answer. i think you're being too strict about the way the question is asked. you know, we're trying to help, not bash some newbies.
– Sedat Kapanoglu
Oct 4 '09 at 7:27
1
I got to this question from 'does php compile to bytecode' in which case I think the difference is relevant.
– xenoterracide
May 31 '12 at 2:32
|
show 3 more comments
This is a meaningless question. PHP uses yacc (bison), just like GCC. yacc is a "compiler compiler". The output of yacc is a compiler. The output of a compiler is "compiled". PHP is parsed by the output of yacc. So it is, by definition, compiled.
If that doesn't satisfy, consider the following. Both php (the binary) and gcc read your source code and produce an abstract syntax tree. Under versions 4 and 5, php then walks the tree to translate the program to bytecode (the compilation step). You can see the bytecode translated to opcodes (which are analogous to assembly) using the Vulcan Logic Dumper. Finally, php (in particular, the Zend engine) interprets the bytecode. gcc, in comparison, walks the tree and outputs assembly; it can also run assemblers and linkers to finish the process. Calling a program handled by one "interpreted" and another program handled by the other "compiled" is meaningless. After all, programs are both run through a "compiler" with both.
You should actually ask the question you want to ask instead. ("Do I pay a performance penalty as PHP recompiles my source code for every request?", etc.)
This is a meaningless question. PHP uses yacc (bison), just like GCC. yacc is a "compiler compiler". The output of yacc is a compiler. The output of a compiler is "compiled". PHP is parsed by the output of yacc. So it is, by definition, compiled.
If that doesn't satisfy, consider the following. Both php (the binary) and gcc read your source code and produce an abstract syntax tree. Under versions 4 and 5, php then walks the tree to translate the program to bytecode (the compilation step). You can see the bytecode translated to opcodes (which are analogous to assembly) using the Vulcan Logic Dumper. Finally, php (in particular, the Zend engine) interprets the bytecode. gcc, in comparison, walks the tree and outputs assembly; it can also run assemblers and linkers to finish the process. Calling a program handled by one "interpreted" and another program handled by the other "compiled" is meaningless. After all, programs are both run through a "compiler" with both.
You should actually ask the question you want to ask instead. ("Do I pay a performance penalty as PHP recompiles my source code for every request?", etc.)
edited Jul 23 '12 at 23:16
outis
59.5k13118177
59.5k13118177
answered Oct 3 '09 at 20:03
jrockwayjrockway
36.1k75785
36.1k75785
4
Tokenizing a source code is not compiling. Even VBScript can be regarded as a compiled language with your definition.
– Sedat Kapanoglu
Oct 3 '09 at 20:13
3
I'm with jrockway on this, although it doesn't really answer the OP's question. It's tempting to create a taxonomy of languages in which every language is placed cleanly into each category. But the reality isn't so neat. Almost every language is a blend of characteristics. Plus, when you get right down to it, even native machine code is "interpreted" by the processor.
– Barry Brown
Oct 3 '09 at 22:33
4
Your high level assertion is correct, this is a meaningless question. Your argument however isn't very helpful, all you've done is taken fuzzy definitions and taken them to extremes. Compilation is the transformation of source into object code. Yes you can consider the transformation of source into a concrete/abstract syntax tree a compilation, but that's not what most people mean is it? Regardless, this is a meaningless question because a language is not INHERENTLY compiled or interpreted, implmentations of a language are compiled or interpreted.
– Falaina
Oct 3 '09 at 23:25
4
let's not oversee that the guy is a beginner. this makes me interpret the question as "does Zend implementation produce native code out of PHP source?". check out my answer. i think you're being too strict about the way the question is asked. you know, we're trying to help, not bash some newbies.
– Sedat Kapanoglu
Oct 4 '09 at 7:27
1
I got to this question from 'does php compile to bytecode' in which case I think the difference is relevant.
– xenoterracide
May 31 '12 at 2:32
|
show 3 more comments
4
Tokenizing a source code is not compiling. Even VBScript can be regarded as a compiled language with your definition.
– Sedat Kapanoglu
Oct 3 '09 at 20:13
3
I'm with jrockway on this, although it doesn't really answer the OP's question. It's tempting to create a taxonomy of languages in which every language is placed cleanly into each category. But the reality isn't so neat. Almost every language is a blend of characteristics. Plus, when you get right down to it, even native machine code is "interpreted" by the processor.
– Barry Brown
Oct 3 '09 at 22:33
4
Your high level assertion is correct, this is a meaningless question. Your argument however isn't very helpful, all you've done is taken fuzzy definitions and taken them to extremes. Compilation is the transformation of source into object code. Yes you can consider the transformation of source into a concrete/abstract syntax tree a compilation, but that's not what most people mean is it? Regardless, this is a meaningless question because a language is not INHERENTLY compiled or interpreted, implmentations of a language are compiled or interpreted.
– Falaina
Oct 3 '09 at 23:25
4
let's not oversee that the guy is a beginner. this makes me interpret the question as "does Zend implementation produce native code out of PHP source?". check out my answer. i think you're being too strict about the way the question is asked. you know, we're trying to help, not bash some newbies.
– Sedat Kapanoglu
Oct 4 '09 at 7:27
1
I got to this question from 'does php compile to bytecode' in which case I think the difference is relevant.
– xenoterracide
May 31 '12 at 2:32
4
4
Tokenizing a source code is not compiling. Even VBScript can be regarded as a compiled language with your definition.
– Sedat Kapanoglu
Oct 3 '09 at 20:13
Tokenizing a source code is not compiling. Even VBScript can be regarded as a compiled language with your definition.
– Sedat Kapanoglu
Oct 3 '09 at 20:13
3
3
I'm with jrockway on this, although it doesn't really answer the OP's question. It's tempting to create a taxonomy of languages in which every language is placed cleanly into each category. But the reality isn't so neat. Almost every language is a blend of characteristics. Plus, when you get right down to it, even native machine code is "interpreted" by the processor.
– Barry Brown
Oct 3 '09 at 22:33
I'm with jrockway on this, although it doesn't really answer the OP's question. It's tempting to create a taxonomy of languages in which every language is placed cleanly into each category. But the reality isn't so neat. Almost every language is a blend of characteristics. Plus, when you get right down to it, even native machine code is "interpreted" by the processor.
– Barry Brown
Oct 3 '09 at 22:33
4
4
Your high level assertion is correct, this is a meaningless question. Your argument however isn't very helpful, all you've done is taken fuzzy definitions and taken them to extremes. Compilation is the transformation of source into object code. Yes you can consider the transformation of source into a concrete/abstract syntax tree a compilation, but that's not what most people mean is it? Regardless, this is a meaningless question because a language is not INHERENTLY compiled or interpreted, implmentations of a language are compiled or interpreted.
– Falaina
Oct 3 '09 at 23:25
Your high level assertion is correct, this is a meaningless question. Your argument however isn't very helpful, all you've done is taken fuzzy definitions and taken them to extremes. Compilation is the transformation of source into object code. Yes you can consider the transformation of source into a concrete/abstract syntax tree a compilation, but that's not what most people mean is it? Regardless, this is a meaningless question because a language is not INHERENTLY compiled or interpreted, implmentations of a language are compiled or interpreted.
– Falaina
Oct 3 '09 at 23:25
4
4
let's not oversee that the guy is a beginner. this makes me interpret the question as "does Zend implementation produce native code out of PHP source?". check out my answer. i think you're being too strict about the way the question is asked. you know, we're trying to help, not bash some newbies.
– Sedat Kapanoglu
Oct 4 '09 at 7:27
let's not oversee that the guy is a beginner. this makes me interpret the question as "does Zend implementation produce native code out of PHP source?". check out my answer. i think you're being too strict about the way the question is asked. you know, we're trying to help, not bash some newbies.
– Sedat Kapanoglu
Oct 4 '09 at 7:27
1
1
I got to this question from 'does php compile to bytecode' in which case I think the difference is relevant.
– xenoterracide
May 31 '12 at 2:32
I got to this question from 'does php compile to bytecode' in which case I think the difference is relevant.
– xenoterracide
May 31 '12 at 2:32
|
show 3 more comments
I know this question is old but it's linked all over the place and I think all answers here are incorrect (maybe because they're old).
There is NO such thing as an interpreted language or a compiled language. Any programming language can be interpreted and/or compiled.
First of all a language is just a set of rules, so when we are talking about compilation we refer to specific implementations of that language.
HHVM, for example, is an implementation of PHP. It uses JIT compilation to transform the code to intermediate HipHop bytecode and then translated into machine code. Is it enough to say it is compiled? Some Java implementations (not all) also use JIT. Google's V8 also uses JIT.
Using the old definitions of compiled vs. interpreted does not make sense nowadays.
"Is PHP compiled?" is a non-sensical question given that there are no
longer clear and agreed delimiters between what is a compiled language vs an
interpreted one.
One possible way to delimit them is (I don't find any meaning in this dichotomy):
compiled languages use Ahead of Time compilation (C, C++);
interpreted languages use Just in Time compilation or no compilation at all (Python, Ruby, PHP, Java).
Doesn't Java use ahead of time compilation in most cases, though? I'm a fairly new Java developer and we usually compile our code way before runtime.
– aCarella
Oct 30 '17 at 12:37
@aCarellain most cases
, yes. in all cases, no. so you cannot draw a line that is semantically significant and agreed.
– Claudiu Creanga
Oct 30 '17 at 14:43
add a comment |
I know this question is old but it's linked all over the place and I think all answers here are incorrect (maybe because they're old).
There is NO such thing as an interpreted language or a compiled language. Any programming language can be interpreted and/or compiled.
First of all a language is just a set of rules, so when we are talking about compilation we refer to specific implementations of that language.
HHVM, for example, is an implementation of PHP. It uses JIT compilation to transform the code to intermediate HipHop bytecode and then translated into machine code. Is it enough to say it is compiled? Some Java implementations (not all) also use JIT. Google's V8 also uses JIT.
Using the old definitions of compiled vs. interpreted does not make sense nowadays.
"Is PHP compiled?" is a non-sensical question given that there are no
longer clear and agreed delimiters between what is a compiled language vs an
interpreted one.
One possible way to delimit them is (I don't find any meaning in this dichotomy):
compiled languages use Ahead of Time compilation (C, C++);
interpreted languages use Just in Time compilation or no compilation at all (Python, Ruby, PHP, Java).
Doesn't Java use ahead of time compilation in most cases, though? I'm a fairly new Java developer and we usually compile our code way before runtime.
– aCarella
Oct 30 '17 at 12:37
@aCarellain most cases
, yes. in all cases, no. so you cannot draw a line that is semantically significant and agreed.
– Claudiu Creanga
Oct 30 '17 at 14:43
add a comment |
I know this question is old but it's linked all over the place and I think all answers here are incorrect (maybe because they're old).
There is NO such thing as an interpreted language or a compiled language. Any programming language can be interpreted and/or compiled.
First of all a language is just a set of rules, so when we are talking about compilation we refer to specific implementations of that language.
HHVM, for example, is an implementation of PHP. It uses JIT compilation to transform the code to intermediate HipHop bytecode and then translated into machine code. Is it enough to say it is compiled? Some Java implementations (not all) also use JIT. Google's V8 also uses JIT.
Using the old definitions of compiled vs. interpreted does not make sense nowadays.
"Is PHP compiled?" is a non-sensical question given that there are no
longer clear and agreed delimiters between what is a compiled language vs an
interpreted one.
One possible way to delimit them is (I don't find any meaning in this dichotomy):
compiled languages use Ahead of Time compilation (C, C++);
interpreted languages use Just in Time compilation or no compilation at all (Python, Ruby, PHP, Java).
I know this question is old but it's linked all over the place and I think all answers here are incorrect (maybe because they're old).
There is NO such thing as an interpreted language or a compiled language. Any programming language can be interpreted and/or compiled.
First of all a language is just a set of rules, so when we are talking about compilation we refer to specific implementations of that language.
HHVM, for example, is an implementation of PHP. It uses JIT compilation to transform the code to intermediate HipHop bytecode and then translated into machine code. Is it enough to say it is compiled? Some Java implementations (not all) also use JIT. Google's V8 also uses JIT.
Using the old definitions of compiled vs. interpreted does not make sense nowadays.
"Is PHP compiled?" is a non-sensical question given that there are no
longer clear and agreed delimiters between what is a compiled language vs an
interpreted one.
One possible way to delimit them is (I don't find any meaning in this dichotomy):
compiled languages use Ahead of Time compilation (C, C++);
interpreted languages use Just in Time compilation or no compilation at all (Python, Ruby, PHP, Java).
edited Dec 28 '15 at 12:23
answered Dec 27 '15 at 21:11


Claudiu CreangaClaudiu Creanga
3,86483276
3,86483276
Doesn't Java use ahead of time compilation in most cases, though? I'm a fairly new Java developer and we usually compile our code way before runtime.
– aCarella
Oct 30 '17 at 12:37
@aCarellain most cases
, yes. in all cases, no. so you cannot draw a line that is semantically significant and agreed.
– Claudiu Creanga
Oct 30 '17 at 14:43
add a comment |
Doesn't Java use ahead of time compilation in most cases, though? I'm a fairly new Java developer and we usually compile our code way before runtime.
– aCarella
Oct 30 '17 at 12:37
@aCarellain most cases
, yes. in all cases, no. so you cannot draw a line that is semantically significant and agreed.
– Claudiu Creanga
Oct 30 '17 at 14:43
Doesn't Java use ahead of time compilation in most cases, though? I'm a fairly new Java developer and we usually compile our code way before runtime.
– aCarella
Oct 30 '17 at 12:37
Doesn't Java use ahead of time compilation in most cases, though? I'm a fairly new Java developer and we usually compile our code way before runtime.
– aCarella
Oct 30 '17 at 12:37
@aCarella
in most cases
, yes. in all cases, no. so you cannot draw a line that is semantically significant and agreed.– Claudiu Creanga
Oct 30 '17 at 14:43
@aCarella
in most cases
, yes. in all cases, no. so you cannot draw a line that is semantically significant and agreed.– Claudiu Creanga
Oct 30 '17 at 14:43
add a comment |
At least it doesn't compile (or should I say optimize) the code as much as one might want it.
This code...
for($i=0;$i<100000000;$i++);
echo $i;
...delays the program equally much each time it is run.
It could have detected that it is a calculation that only needs to be done the first time.
Now we have a option called generators.
– Ankit Vishwakarma
Feb 5 '16 at 18:56
add a comment |
At least it doesn't compile (or should I say optimize) the code as much as one might want it.
This code...
for($i=0;$i<100000000;$i++);
echo $i;
...delays the program equally much each time it is run.
It could have detected that it is a calculation that only needs to be done the first time.
Now we have a option called generators.
– Ankit Vishwakarma
Feb 5 '16 at 18:56
add a comment |
At least it doesn't compile (or should I say optimize) the code as much as one might want it.
This code...
for($i=0;$i<100000000;$i++);
echo $i;
...delays the program equally much each time it is run.
It could have detected that it is a calculation that only needs to be done the first time.
At least it doesn't compile (or should I say optimize) the code as much as one might want it.
This code...
for($i=0;$i<100000000;$i++);
echo $i;
...delays the program equally much each time it is run.
It could have detected that it is a calculation that only needs to be done the first time.
edited Nov 8 '11 at 20:31


chown
42.2k16116160
42.2k16116160
answered Nov 8 '11 at 19:51
Magnus AnderssonMagnus Andersson
18112
18112
Now we have a option called generators.
– Ankit Vishwakarma
Feb 5 '16 at 18:56
add a comment |
Now we have a option called generators.
– Ankit Vishwakarma
Feb 5 '16 at 18:56
Now we have a option called generators.
– Ankit Vishwakarma
Feb 5 '16 at 18:56
Now we have a option called generators.
– Ankit Vishwakarma
Feb 5 '16 at 18:56
add a comment |
PHP is an interpreted language but the program used to interpret PHP is complied.
PHP compiler generates the bytecode which is machine independents later this bytecode converts into machine understandable code by run time engine.
add a comment |
PHP is an interpreted language but the program used to interpret PHP is complied.
PHP compiler generates the bytecode which is machine independents later this bytecode converts into machine understandable code by run time engine.
add a comment |
PHP is an interpreted language but the program used to interpret PHP is complied.
PHP compiler generates the bytecode which is machine independents later this bytecode converts into machine understandable code by run time engine.
PHP is an interpreted language but the program used to interpret PHP is complied.
PHP compiler generates the bytecode which is machine independents later this bytecode converts into machine understandable code by run time engine.
answered Aug 24 '17 at 13:56


Rahul ChauhanRahul Chauhan
463610
463610
add a comment |
add a comment |
Its interpreted. So keep that in mind when you put too many comments in your code...
1
This answer would have been true for BASIC.
– Barry Brown
Oct 3 '09 at 20:19
1
Why -3? This answer is true, even for php. The analyzation of whether an instruction is a comment just takes an unsignificant amount of time.
– Atmocreations
Oct 3 '09 at 21:24
You take the hit only the first time your script is used.
– Barry Brown
Oct 3 '09 at 23:20
3
I've never looked at code and thought "if only it used fewer comments, then all our performance problems would go away!" And neither have you.
– JohnFF
Jul 3 '17 at 12:45
1
@Dheeraj: I wasn't talking about small to moderate number of comments. I'm talking about not including your entire doc as pure comments in your code. All of you are freaking out like I'm saying "NEVER PUT COMMENTS IN YOUR CODE HUR HUR HUR.". No. That's not what I said. If you do actually put hundreds of thousands of lines of comments in your small PHP application, then perhaps you do need a better documentation system, and write more readable code while you're at it.
– Stanislav Palatnik
Aug 6 '17 at 17:39
|
show 2 more comments
Its interpreted. So keep that in mind when you put too many comments in your code...
1
This answer would have been true for BASIC.
– Barry Brown
Oct 3 '09 at 20:19
1
Why -3? This answer is true, even for php. The analyzation of whether an instruction is a comment just takes an unsignificant amount of time.
– Atmocreations
Oct 3 '09 at 21:24
You take the hit only the first time your script is used.
– Barry Brown
Oct 3 '09 at 23:20
3
I've never looked at code and thought "if only it used fewer comments, then all our performance problems would go away!" And neither have you.
– JohnFF
Jul 3 '17 at 12:45
1
@Dheeraj: I wasn't talking about small to moderate number of comments. I'm talking about not including your entire doc as pure comments in your code. All of you are freaking out like I'm saying "NEVER PUT COMMENTS IN YOUR CODE HUR HUR HUR.". No. That's not what I said. If you do actually put hundreds of thousands of lines of comments in your small PHP application, then perhaps you do need a better documentation system, and write more readable code while you're at it.
– Stanislav Palatnik
Aug 6 '17 at 17:39
|
show 2 more comments
Its interpreted. So keep that in mind when you put too many comments in your code...
Its interpreted. So keep that in mind when you put too many comments in your code...
answered Oct 3 '09 at 19:58
Stanislav PalatnikStanislav Palatnik
3,46033664
3,46033664
1
This answer would have been true for BASIC.
– Barry Brown
Oct 3 '09 at 20:19
1
Why -3? This answer is true, even for php. The analyzation of whether an instruction is a comment just takes an unsignificant amount of time.
– Atmocreations
Oct 3 '09 at 21:24
You take the hit only the first time your script is used.
– Barry Brown
Oct 3 '09 at 23:20
3
I've never looked at code and thought "if only it used fewer comments, then all our performance problems would go away!" And neither have you.
– JohnFF
Jul 3 '17 at 12:45
1
@Dheeraj: I wasn't talking about small to moderate number of comments. I'm talking about not including your entire doc as pure comments in your code. All of you are freaking out like I'm saying "NEVER PUT COMMENTS IN YOUR CODE HUR HUR HUR.". No. That's not what I said. If you do actually put hundreds of thousands of lines of comments in your small PHP application, then perhaps you do need a better documentation system, and write more readable code while you're at it.
– Stanislav Palatnik
Aug 6 '17 at 17:39
|
show 2 more comments
1
This answer would have been true for BASIC.
– Barry Brown
Oct 3 '09 at 20:19
1
Why -3? This answer is true, even for php. The analyzation of whether an instruction is a comment just takes an unsignificant amount of time.
– Atmocreations
Oct 3 '09 at 21:24
You take the hit only the first time your script is used.
– Barry Brown
Oct 3 '09 at 23:20
3
I've never looked at code and thought "if only it used fewer comments, then all our performance problems would go away!" And neither have you.
– JohnFF
Jul 3 '17 at 12:45
1
@Dheeraj: I wasn't talking about small to moderate number of comments. I'm talking about not including your entire doc as pure comments in your code. All of you are freaking out like I'm saying "NEVER PUT COMMENTS IN YOUR CODE HUR HUR HUR.". No. That's not what I said. If you do actually put hundreds of thousands of lines of comments in your small PHP application, then perhaps you do need a better documentation system, and write more readable code while you're at it.
– Stanislav Palatnik
Aug 6 '17 at 17:39
1
1
This answer would have been true for BASIC.
– Barry Brown
Oct 3 '09 at 20:19
This answer would have been true for BASIC.
– Barry Brown
Oct 3 '09 at 20:19
1
1
Why -3? This answer is true, even for php. The analyzation of whether an instruction is a comment just takes an unsignificant amount of time.
– Atmocreations
Oct 3 '09 at 21:24
Why -3? This answer is true, even for php. The analyzation of whether an instruction is a comment just takes an unsignificant amount of time.
– Atmocreations
Oct 3 '09 at 21:24
You take the hit only the first time your script is used.
– Barry Brown
Oct 3 '09 at 23:20
You take the hit only the first time your script is used.
– Barry Brown
Oct 3 '09 at 23:20
3
3
I've never looked at code and thought "if only it used fewer comments, then all our performance problems would go away!" And neither have you.
– JohnFF
Jul 3 '17 at 12:45
I've never looked at code and thought "if only it used fewer comments, then all our performance problems would go away!" And neither have you.
– JohnFF
Jul 3 '17 at 12:45
1
1
@Dheeraj: I wasn't talking about small to moderate number of comments. I'm talking about not including your entire doc as pure comments in your code. All of you are freaking out like I'm saying "NEVER PUT COMMENTS IN YOUR CODE HUR HUR HUR.". No. That's not what I said. If you do actually put hundreds of thousands of lines of comments in your small PHP application, then perhaps you do need a better documentation system, and write more readable code while you're at it.
– Stanislav Palatnik
Aug 6 '17 at 17:39
@Dheeraj: I wasn't talking about small to moderate number of comments. I'm talking about not including your entire doc as pure comments in your code. All of you are freaking out like I'm saying "NEVER PUT COMMENTS IN YOUR CODE HUR HUR HUR.". No. That's not what I said. If you do actually put hundreds of thousands of lines of comments in your small PHP application, then perhaps you do need a better documentation system, and write more readable code while you're at it.
– Stanislav Palatnik
Aug 6 '17 at 17:39
|
show 2 more comments
Traditional categorization of compilers and interpreters is blurry in case of just-in-time compilation and bytecode interpretation.PHP is interpreted.But,that does not mean that PHP is not compiled.PHP compiler perform syntax checking,intermediate code generation and optimization.PHP is interpreted because object code that PHP compiler generates is parsed by another precompiled native binary.Which interprets intermediate code to cpu readable instruction.Thats why no other language can be as first as assembly language in term of instruction execution.Because, instructions a assembler( assembly compiler) produce are already there in cpu.
add a comment |
Traditional categorization of compilers and interpreters is blurry in case of just-in-time compilation and bytecode interpretation.PHP is interpreted.But,that does not mean that PHP is not compiled.PHP compiler perform syntax checking,intermediate code generation and optimization.PHP is interpreted because object code that PHP compiler generates is parsed by another precompiled native binary.Which interprets intermediate code to cpu readable instruction.Thats why no other language can be as first as assembly language in term of instruction execution.Because, instructions a assembler( assembly compiler) produce are already there in cpu.
add a comment |
Traditional categorization of compilers and interpreters is blurry in case of just-in-time compilation and bytecode interpretation.PHP is interpreted.But,that does not mean that PHP is not compiled.PHP compiler perform syntax checking,intermediate code generation and optimization.PHP is interpreted because object code that PHP compiler generates is parsed by another precompiled native binary.Which interprets intermediate code to cpu readable instruction.Thats why no other language can be as first as assembly language in term of instruction execution.Because, instructions a assembler( assembly compiler) produce are already there in cpu.
Traditional categorization of compilers and interpreters is blurry in case of just-in-time compilation and bytecode interpretation.PHP is interpreted.But,that does not mean that PHP is not compiled.PHP compiler perform syntax checking,intermediate code generation and optimization.PHP is interpreted because object code that PHP compiler generates is parsed by another precompiled native binary.Which interprets intermediate code to cpu readable instruction.Thats why no other language can be as first as assembly language in term of instruction execution.Because, instructions a assembler( assembly compiler) produce are already there in cpu.
answered Oct 7 '11 at 9:58
suruzsuruz
261
261
add a comment |
add a comment |
It is interpreted as PHP code is interpreted by an engine(commonly converted into bytecode first); it is also compiled as some tools can compile PHP code into the an executable, like phc.
add a comment |
It is interpreted as PHP code is interpreted by an engine(commonly converted into bytecode first); it is also compiled as some tools can compile PHP code into the an executable, like phc.
add a comment |
It is interpreted as PHP code is interpreted by an engine(commonly converted into bytecode first); it is also compiled as some tools can compile PHP code into the an executable, like phc.
It is interpreted as PHP code is interpreted by an engine(commonly converted into bytecode first); it is also compiled as some tools can compile PHP code into the an executable, like phc.
answered Aug 22 '14 at 8:13
tz_sztz_sz
123
123
add a comment |
add a comment |
Obviously php.exe
(the PHP interpreter) is a compiled executable.
However, I don't think that's what you asked.
When a PHP script is loaded, it get's compiled into a binary format known as Zend opcodes, into the memory, which are then interpreted efficiently.
Source: https://stackoverflow.com/a/18595821/3881189
add a comment |
Obviously php.exe
(the PHP interpreter) is a compiled executable.
However, I don't think that's what you asked.
When a PHP script is loaded, it get's compiled into a binary format known as Zend opcodes, into the memory, which are then interpreted efficiently.
Source: https://stackoverflow.com/a/18595821/3881189
add a comment |
Obviously php.exe
(the PHP interpreter) is a compiled executable.
However, I don't think that's what you asked.
When a PHP script is loaded, it get's compiled into a binary format known as Zend opcodes, into the memory, which are then interpreted efficiently.
Source: https://stackoverflow.com/a/18595821/3881189
Obviously php.exe
(the PHP interpreter) is a compiled executable.
However, I don't think that's what you asked.
When a PHP script is loaded, it get's compiled into a binary format known as Zend opcodes, into the memory, which are then interpreted efficiently.
Source: https://stackoverflow.com/a/18595821/3881189
edited May 23 '17 at 12:03
Community♦
11
11
answered Mar 8 '17 at 5:40


FluorescentGreen5FluorescentGreen5
459418
459418
add a comment |
add a comment |
php is Interpreter, You don't compile it, you save it in file and server reads it line by line. C++ is compiled, you compile the whole script and then run the exe, your program. Too late to make changes now.
add a comment |
php is Interpreter, You don't compile it, you save it in file and server reads it line by line. C++ is compiled, you compile the whole script and then run the exe, your program. Too late to make changes now.
add a comment |
php is Interpreter, You don't compile it, you save it in file and server reads it line by line. C++ is compiled, you compile the whole script and then run the exe, your program. Too late to make changes now.
php is Interpreter, You don't compile it, you save it in file and server reads it line by line. C++ is compiled, you compile the whole script and then run the exe, your program. Too late to make changes now.
answered Oct 18 '17 at 11:22


bujashakabujashaka
62
62
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f1514676%2fis-php-compiled-or-interpreted%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown