Re: concat vs variable in string
- From: Gordon <gordon.mcvey@xxxxxxxxxxxx>
- Date: Thu, 14 Aug 2008 05:55:31 -0700 (PDT)
On Aug 13, 11:58 pm, Mark <mnbaya...@xxxxxxxxx> wrote:
Is
"{$_SERVER['DOCUMENT_ROOT']}/inc/mysql-connect.php"
more efficient than
$_SERVER['DOCUMENT_ROOT']."/inc/mysql-connect.php"
?
Or does it still do a concatenation behind the scenes? I hear
concatenation is expensive... (even if its negligible in this scenario)
If you use single quotes instead of double, then PHP won't attempt to
do variable substitution on a string, which is where the real cost
lies. However, I don't think there's a great deal of difference
between var subbing in double quotes and concatting with single quotes
and variables. My understanding is that concatting is slightly
faster, but the differences aren't huge unless you're working with
massive strings or a long loop.
The bigger advantage, as far as I'm concerned, is that with the
variables not inside strings they get syntax highlighted, whereas they
don't when they're embedded in a string. additionally, as PHP is more
often than not outputting HTML and XML, where attributes are expected
to be wrapped in double quoted strings, using single quoted strings
means you usually don't have to rely on escaping quote characters to
get the correct output.
.
- Follow-Ups:
- Re: concat vs variable in string
- From: Charles Calvert
- Re: concat vs variable in string
- References:
- concat vs variable in string
- From: Mark
- concat vs variable in string
- Prev by Date: Re: php mmap and munmap
- Next by Date: Re: any php/css parsers out there?
- Previous by thread: Re: concat vs variable in string
- Next by thread: Re: concat vs variable in string
- Index(es):
Relevant Pages
|