On Friday, October 24, 2003, at 10:43 AM, Shawn McKenzie wrote:

For example it is better to code:
      Code:
      echo '<td bgcolor="'.$bgcolor2.'">&nbsp;</td></tr>';

vs.
      Code:
      echo "<td bgcolor=\"$bgcolor2\">&nbsp;</td></tr>";


"Better" is a very loose term, but I've adopted a coding style which uses single quotes on all lines which don't require special characters (\n, \t, etc) or variables.


At the same time, I dropped double quotes within my HTML where possible, realising that most of my echo's had double quotes, so I was escaping a lot of quotes.

I also adapted wrapping all variables in {parenthesis} so that PHP has no chance of being confused

On all but the most heavily visited sites, it's my humble opinion that you should take the approach of what's fast for you to code, read, maintain and re-develop, rather than what might get you a .000000000001 % performance gain -- this is most likely due to the nature of the sites I develop -- but this seems to be the general consensus I've read over many years and from many sources.

No special chars or vars:
echo '<td bgcolor=\'#ffffff\'>&nbsp;</td></tr>';

For cases with vars and special chars, I think these look terrible:
echo '<td bgcolor="'.$bgcolor2.'">&nbsp;</td></tr>';
echo "<td bgcolor=\"$bgcolor2\">&nbsp;</td></tr>";

Whereas this is clear and easy to work with:
echo "<td bgcolor='{$bgcolor2}'>&nbsp;</td></tr>";

You mileage will vary, but unless you're working on a hugely successful site (the kind that needs a dedicated server), take your personal preferences, and long-term readability and maintainability into account when deciding what suits you.


Justin


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



Reply via email to