Re: Coding Style Question...
| From: | Glenn Richmond | Date: | Tue, 03 Oct 2006 02:23:30 +0000 |
| Subject: | Re: Coding Style Question... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-242525@lists.php.net to get a copy of this message | ||
Hi Tony,
Sounds like a good start. I have to admit that one that I prefer is that
HTML code should be completely separated from PHP via the use of a
templating engine of some sort (I'm a fan of XTemplate). I'll probably
get strong opposition for these comments, but in my opinion, there's
nothing worse than mixing two different lanuages in a single file, not
to mention mixing functional code with layout code.
Glenn.
Tony Di Croce wrote:
> I am relatively new to PHP... I have about 1.5 years of light PHP work
> under
> my belt... Over the past year or so my PHP coding style has evolved
> significantly and I'm curious as to how experienced programmers write
> PHP...
>
> Basically, here is what I have evolved to:
>
> 1) ALL php code is at the top of the file.
> 2) ALL html code is in a here document at the bottom.
> 3) php code is run before 1 character is outputed (and hence, no
> headers are
> sent, leaving redirects open for possibilities)
> 4) I almost always following my require_once directives with a
> session_start() at the top of the file.
> 5) Often, my forms submit to the PHP page that generated them but do
> so with
> a hidden posted variable. If that variable is set, then I process the
> form
> submission.
>
> I think the most important part of all this is #1 & #2... I think I am
> using
> PHP a little like template engine this way...
>
> It seems to me that I most often see code snippets that try to intertwine
> HTML and PHP, but in my experience, except for trivial examples, this
> doesn't work so good...
>
> What do you think?
>