Re: Back to Basics - Why Use Single Quotes?

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

 



Eric Butera wrote:
On Wed, Jul 30, 2008 at 6:51 PM, Stephen <stephen-d@xxxxxxxxxx> wrote:
I have traditionally used double quotes going back to my PASCAL days.

I see many PHP examples using single quotes, and I began to adopt that
convention.

Even updating existing code.

And I broke some stuff that was doing variable expansion. So I am back to
using double quotes.

But I wonder, is there any reason to use single quotes?

Stephen

Because sometimes it is nice to do this:

$onclick = ' onclick="..."'

Not having to escape my single tick makes it more readable.


Now *that's* a good reason... anything that means fewer \'s or \"s.
I often go for HEREDOC syntax if the backslashes start taking over - readability is much more important to me than nanoseconds of performance.

There's also the case where you might want literal $s in your string:
e.g.
$foo = 'You need to pay $dollars...';

compared with

$foo = "You need to pay \$dollars...";

Again, it depends on you view of backslashes.


--
Peter Ford                              phone: 01580 893333
Developer                               fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

--
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