RE: [PHP] Code optimization: single vs. double quotes?

This is a discussion on RE: [PHP] Code optimization: single vs. double quotes? within the PHP General forums, part of the PHP Programming Forums category; olinux <mailto:olnx@yahoo.com> on Friday, October 24, 2003 9:41 PM said: >>> echo &...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-27-2003
Chris W. Parker
 
Posts: n/a
Default RE: [PHP] Code optimization: single vs. double quotes?

olinux <mailto:olnx@yahoo.com>
on Friday, October 24, 2003 9:41 PM said:

>>> echo "<td bgcolor=\"$bgcolor2\">&nbsp;</td></tr>";

>
> uggh - apparently you've never had to redesign a
> site/application that uses this style. This is one
> table cell, but when you work this style through a big
> app, it's a huge pain (waste of time) to make any
> changes.


Apparently. What do you recommend?



c.

--
Don't like reformatting your Outlook replies? Now there's relief!
http://home.in.tum.de/~jain/software/outlook-quotefix/
Reply With Quote
  #2 (permalink)  
Old 10-27-2003
Justin French
 
Posts: n/a
Default Re: [PHP] Code optimization: single vs. double quotes?

On Tuesday, October 28, 2003, at 04:29 AM, Chris W. Parker wrote:

> olinux <mailto:olnx@yahoo.com>
> on Friday, October 24, 2003 9:41 PM said:
>
>>>> echo "<td bgcolor=\"$bgcolor2\">&nbsp;</td></tr>";

>>
>> uggh - apparently you've never had to redesign a
>> site/application that uses this style. This is one
>> table cell, but when you work this style through a big
>> app, it's a huge pain (waste of time) to make any
>> changes.

>
> Apparently. What do you recommend?


You have plenty of options... a & b would be my preference:

a) echo "<td bgcolor='{$bgcolor2}'>&nbsp;</td></tr>";
b) echo "<td bgcolor='$bgcolor2'>&nbsp;</td></tr>";
c) echo '<td bgcolor="'.$bgcolor2.'">&nbsp;</td></tr>';
d) echo "<td bgcolor='".$bgcolor2."'>&nbsp;</td></tr>";


Justin French
Reply With Quote
  #3 (permalink)  
Old 10-27-2003
Chris Shiflett
 
Posts: n/a
Default Re: [PHP] Code optimization: single vs. double quotes?

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

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

Chris

=====
My Blog
http://shiflett.org/
HTTP Developer's Handbook
http://httphandbook.org/
RAMP Training Courses
http://www.nyphp.org/ramp
Reply With Quote
  #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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 11:36 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0