Re: Coding Style Question...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, October 2, 2006 7:32 pm, 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?

I do the same, but will mingle HTML/PHP for layout/formatting or User
Interface logic.

And I don't bother with a heredoc, since I find it easier to edit HTML
with the occasional <?php echo $foo?> in it.

E.g., a popup menu of the years from "current" to 10 years into the
future for the credit card expiration is not exactly complex back-end
business logic.  A simple 'for' loop in my HTML to do that is vastly
superior to the "solution" of templates that require hours of
back-tracking through 7 PHP/template/HTML/whatever files to sort out
what the heck is going on here...

And, yes, I *did* once waste hours to find out how they were
generating a 10-year popup for the credit card expiration... Which
they had HARD-CODED the 'start' year in their business logic!!! 
Sheesh!  Back-tracking that through the files turned a 5-minute task
into hours wasted.  And folks wonder why I think PHP *is* a template
language and you shouldn't use another one on top of it...

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux