I am a recent fan of the single-quotes. I used to use double only but when some gurus
told me the disadvantages I converted my entire project over to single quotes. Single
quotes are ideal because as far coding goes it greatly decreases the time of
development when you don't have to worry about dropping in the escape character on
your HTML values, etc. Granted, single quotes can be a nuisance in some instances
(like when you need a new line character) but of course there is a way around. I
simply define a constant and call that at the end of every line in order to substitute
for the new line character.
Horizontal Tab - define("T", chr(9));
New Line - define("NL", chr(10));
Cheers,
Nathan
----- Original Message -----
From: Robert Cummings
To: Shawn McKenzie
Cc: PHP-General
Sent: Thursday, October 23, 2003 10:30 PM
Subject: Re: [PHP] Code optimization: single vs. double quotes?
On Thu, 2003-10-23 at 20:43, Shawn McKenzie wrote:
> I came across this post and was hoping to get a gurus opinion on the
> validity. TIA
>
> -Shawn
>
> I remember reading somewhere re: PHP coding that it is a better coding
> practice to use single quotes as much as possible vs. using double quotes in
> scripts. When using double quotes, you are forcing PHP to look for variables
> within them, even though there may not be any, thus slowing execution
> time...
>
> For example it is better to code:
> Code:
> echo '<td bgcolor="'.$bgcolor2.'"> </td></tr>';
>
> vs.
> Code:
> echo "<td bgcolor=\"$bgcolor2\"> </td></tr>";
Better is a very subjective question; however, style 1 will run faster
since it won't look for variable interpolation. Personally I always use
style 1 unless I specifically need variable interpolation or one of the
special characters such as a newline. Also when doing HTML the double
quotes fit nicely in the the single quote paradigm. On the other hand
when I do SQL queries, I often allow interpolation just because it is
more readable and because I usually use single quotes to wrap strings in
my queries.
HTH,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php