Re: using . to concatenate strings ?

From: Date: Thu, 04 Dec 2003 08:56:21 +0000
Subject: Re: using . to concatenate strings ?
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-24122@lists.php.net to get a copy of this message
On Thu, 4 Dec 2003 at 09:48:10, Arnaud Limbourg wrote: > i have a php question. > > What is the best way to go ? > > $str = 'text ' . $obj->myvar . ' extrat text'; > > or > > $str = "text {$obj->myvar} extrat text'; > > Does one have advantages over the other ? I prefer the first solution since it's clear which parts are handled as variable-names and which are handled as test. Mixing text and variables (evaluation of variable names "inside" a string does work - but in my oppinion it makes the sourcecode less readable, manageable and leads to more errors. With the var-in-string-solution there are also other drawbacks like problems with syntax highlighting etc. Hehe - one funny example - what output do you expect? echo $a-$b; echo "$a-$b"; :-)) It may be up to personal preferences - but I suggest you make clear at which points you use vars and at which you use strings. Regards, Stefan

« previous php.pear.dev (#24122) next »