On Fri, 2009-02-27 at 08:43 -0500, Bob McConnell wrote:
> From: Hans Schultz
> > 
> > Hahahah,I was thinking the same thing :D
> > 
> > --- On Fri, 2/27/09, Ashley Sheridan <a...@ashleysheridan.co.uk> wrote:
> > From: Ashley Sheridan <a...@ashleysheridan.co.uk>
> > Subject: Re: [PHP] "use strict" or similar in PHP?
> > To: "Hans Schultz" <h.schult...@yahoo.com>
> > Cc: php-general@lists.php.net, "9el" <le...@phpxperts.net>
> > Date: Friday, February 27, 2009, 1:11 PM
> > 
> > On Fri, 2009-02-27 at 14:04 +0100, Hans Schultz wrote:
> >> Sorry, I didn't want to offend anyone :-) It was just very weird
> > argument  
> >> - to quote:
> >> "There is no "compile" time.  PHP is interpreted so it is
> > compiled and  
> >> then executed."
> >> Sounds like contradiction in this very sentence :-).
> >> 
> >> My apologies
> >> 
> > But if it never compiles, it can never run, but it can't run without
> > compiling? Arggh, my head. So does that mean if I go back in time and
> > shoot my grandfather, then nobody is in the woods to hear PHP try to
> > compile?
> The compile process parses the text of the source file and translates it
> into an alternate form. This can by byte code, ala Pascal and Java, or
> executable code, ala COBOL and C. An interpreter, on the other hand,
> simply parses the source file, line by line and executes each line as it
> reads it, usually without saving it in an alternate form. This is the
> way JavaScript works. Some languages, such as Perl, are somewhere
> between the two. Perl parses the whole file, then executes only if it
> did not find any syntax errors or undefined variables (if certain
> strictures are turned on). Otherwise it prints out only the error
> message.
> >From what I have seen of PHP, it is strictly interpreted. i.e. a line is
> read, and executed. Then the next line is read, and executed. etc. So
> there is no way to get it to block execution from the beginning even
> when there are fatal errors. It will already have printed out as much of
> the page as it executed before it finds those errors. This works fine in
> a development or test environment, but is a serious problem in
> production.
> So, I believe the question that was actually asked, is there any way to
> induce PHP to completely parse the source file(s) and report any errors
> before printing out anything, even the HTTP headers? Or can I set it to
> redirect to an error page instead of sending an incomplete target page
> with error messages that might reveal information I don't want exposed?

No, PHP is not strictly interpreted. You are confusing run-time includes
with strict interpretation. PHP parses a source file completely before
executing the code. The problem is when you make use of require() or
include(). In these cases the parsing is defered until such time as the
logic warrants inclusion of the source code. This is advantageous since
compilation need not be performed for source code not being used by a
page. However, as you have duly noted, you cannot detect parse errors
before any content is sent to the browser for such included source
(unless you use output buffering). However, there is a simple
command-line facility to check the parsability of your source code
before releasing it for public consumption:

    php -l <source.php>

Application and Templating Framework for PHP

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to