PHP is an interpreted language, not compiled. Yet I have come across a book that mentions stuff happening in PHP at compile time, and the PHP manual states that declaring a const happens at compile-time. How is the term compile-time used in relation to PHP since PHP isn't compiled?
If it is just meant as "when the script is read and translated into the interpreters subroutines", then what is the difference between the terms compile-time and run-time?
Compile time is the period when the programming code (such as C#, Java, C, Python) is converted to the machine code (i.e. binary code). Runtime is the period of time when a program is running and generally occurs after compile time.
Basically, PHP is interpreted but PHP is compiled down to an intermediate bytecode that is then interpreted by the runtime Zend engine.
In computer science, compile time (or compile-time) describes the time window during which a computer program is compiled. The term is used as an adjective to describe concepts related to the context of program compilation, as opposed to concepts related to the context of program execution (runtime).
Compile time address binding is done before loading the program into memory. Execution time address binding is done at the time of program execution. Instructions are translated into absolute address. It helps in execution.
PHP source code goes through a step where it is compiled into PHP Opcode. This idea has been implemented in a variety of platforms, most notably with Java. Theoretically, by having a separate "virtual machine" runtime to run the Opcodes, the language designers are able to separate the language from portability issues.
You can find a list of these Opcodes in the manual
In a typical PHP environment with no opcode caching, the compilation step and the "run-time" step are indistinguishable, however, when you introduce an "accelerator/opscode cache" like APC or the Zend Platform product, you can see that these are separate steps in the process.
Once a script has been compiled into PHP Opscodes, it can be run from cache without having to be re-compiled from source, which is where these accelerators can greatly improve performance.
If you focus in on the "runtime" aspect of PHP you see the "Interpreted" nature of PHP, as it requires a runtime environment, when compared to a compiled/linked language like c/c++ that runs as a native operating system program.
In the case of PHP, the php program is the native operating system program (or native as a module of a native OS web server).
Not unlike the way Java runs inside of the "Java Virtual Machine (JVM)" PHP's scripts are running inside PHP and thus don't contain the specifics of how the operations are going to be natively performed by the OS.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With