View Single Post

  #4 (permalink)  
Old 10-28-2003
Justin French
 
Posts: n/a
Default Re: [PHP] Code optimization: single vs. double quotes?

On Tuesday, October 28, 2003, at 09:29 AM, Chris Shiflett wrote:

> --- Justin French <justin@indent.com.au> wrote:
>> a) echo "<td bgcolor='{$bgcolor2}'>&nbsp;</td></tr>";

>
> The curly braces are superfluous here, since you are using double
> quotes. I'm
> not sure if you like having them there, but I think that less syntax
> yields a
> simpler and cleaner appearance.


Yes, they are superfluous in this example, but not because we're in
double quotes. You can ONLY use complex strings inside double quotes,
AFAIK:

<?
$str = "blah";
echo "{$str}<br />"; // echos blah<br />
echo '{$str}<br />'; // echos {$str}<br />
?>

As I'm sure you're aware, the use of the {braces} is to allow complex
combinations of variables, like found in the manual
http://www.php.net/types.string


In the above example, they are indeed not needed, but I've gotten into
the habbit of using them on all strings for a few reasons;

- the fact that there can be no confusion (either human or PHP) over
what I mean
- PHP will be non-greedy when looking for the valid variable name
- since i'm now in the habbit, I never have to debug examples where it
IS needed :)


> However, I hate single quotes around HTML attributes, so I can't bring
> myself
> to use that format anyway. :-)


Well, that's where we come down to personal opinion... personally,
seeing \" 100's of times in a script doesn't turn me on at all :)


Justin French
Reply With Quote