View Single Post

  #16 (permalink)  
Old 05-12-2008
Sir Robin
 
Posts: n/a
Default Re: Tool to parse and validate PHP script?

On Sat, 10 May 2008 15:29:34 -0400, Jerry Stuckle <jstucklex@attglobal.net>
wrote:

>>>> Hello
>>>>
>>>> Is there a tool on Linux/FreeBSD that can parse a PHP script to make
>>>> sure there's no compile-time issues?
>>> You will never have a compile-time error with PHP since PHP is a script
>>> and, hence, doesn't compile. Perhaps you mean run-time issues?

>>
>> As far as I understand PHP does in fact first compile the script to byte-code
>> and then run it... Surely if the code has syntax errors it would result to
>> compile time error, right?
>>

>
>No, Gilles is correct. PHP is not compiled. It is interpreted. A big
>difference.


I learned when I started using PHP Accelerator on my server that there are
several similiar PHP accelerating systems and all of them are based on caching
compiled bytecode of PHP scripts to avoid compiling the code on every request
and recompiling the code to cache happens only when the accelerator sees that
the source file has been modified after the last bytecode of it was cached.

That would not make no sense whatsoever if PHP did not compile to bytecode.
You are right on saying that it's interprepted too though as the bytecode
still needs to be interprepted...

>And no, syntax errors are not considered compile-time errors.
>
>Java, OTOH, is compiled to byte code.


....yes, the difference between Java and PHP is not that PHP is not compiled.
It's that java has to be compiled first with java bytecode compiler as java
run time environment expects to get bytecode, not java code. PHP then again
(like several other languages, perl for one) compiles by default the source on
request but it still compiles to bytecode first and then runs the bytecode.
And why is this? Because bytecode is faster to interprept&run than
non-compiled source code which makes any program that runs loops, calls same
functions many times during executions, etc. as the interprepter would have to
parse the same uncompiled part of code every time it's run.

Compiling scripts to bytecode is fast with pretty much any other language than
Java and the bytecode is usually simply the script converted to format
designed to have nothing but the minimal info that is needed for running it as
fast as possible.

Thus I conclude that PHP does compile to bytecode but it is regularly compiled
at request by PHP interprepters built-in run time compiler.

--
***/--- Sir Robin (aka Jani Saksa) Bi-Sex and proud of it! ---\***
**/ email: robsku@fiveam.NO-SPAM.org, <*> Reg. Linux user #290577 \**
*| Me, Drugs, DooM, Photos, Writings... http://soul.fiveam.org/robsku |*
**\--- GSM/SMS: +358 44 927 3992 ---/**
"Sir Robin valehtelee järjestelmällisesti" - Nikolas Mäki
Reply With Quote