[ciapug] Peer review of PHP code

Barry Von Ahsen ciapug@cialug.org
Tue, 13 Apr 2004 11:12:54 -0500


Claus wrote:

> On 4/12/2004 4:28 PM, Barry Von Ahsen wrote:
> 
>> I personally turn the interpreter on and off as necessary (ie. not 
>> writing html with php), but that's a personal preference (plus then 
>> the syntax checker checks the html syntax, not the php).  I know this 
>> was bad performance-wise with ASP2.0/IIS4, but I haven't heard of any 
>> problems with php.
> 
> 
> I've been arguing about this with myself a bit, too.  Somehow the 
> consistant use of php appealed to me better than going in and out of 
> PHP.  Especially since that page is more logic driven.
 >
> The page that actually presents the newsletters to the viewer is HTML 
> with PHP embedded.  There the program/parse flow is straight forward.
> 
> As far as HTML syntax checker goes, I would run them after the web 
> server has parsed/served the page since that's what is actually passed 
> to the browser.  But the reality is that I never bother with syntax 
> checkers.  My most advanced HTML tag is the <table> tag.  Never really 
> had time to embrace the CSS front although it looks promising.

I guess I meant code-colorers.  I use Dreamweaver MX to do most of my 
development, and it's smart enought to determine what is html and what 
is php in a line like:
<input type="text" name="firstname" value="<?= $firstname; ?>">
or
<option value="True"<? if($selectbox=="True") { echo " selected"; } ?>>
Then if I forget the " after =="True, the code-colorer will color it 
like a runaway string and I get a visual clue of an error before the php 
interpreter gives me one.

but trying to syntax check (specificaly to validate the html) it usually 
barfs on the php.  especially when I'm making table rows in a loop; if I 
have something like:
<? if($i%2 == 0) { ?>
	<tr bgcolor="#eeeeee">
<? } else { ?>
	<tr bgcolor="#ffffff">
<? } ?>
	<td>stuff</td>
</tr>
it will complain "No starting tag found for: "tr", or it was closed too 
many times".  I see it's there, but only because I'm mentally 
interpreting the php, if I were to give it just the final output (like 
you do) it would be fine.

-barry