NYCPHP Meetup

NYPHP.org

[nycphp-talk] single quote vs. double quote

David Krings ramons at gmx.net
Wed Apr 4 20:22:33 EDT 2007


Paul Houle wrote:
> David Krings wrote:
>> Paul Houle wrote:
>>>    (4) Make a habit of writing {$like_this}
>>
>> Can you elaborate on this? Me guessing of what you mean is probably 
>> not a good approach. Thanks in advance.
>>
>    There's a short form and long form of substitution in PHP.  The short 
> form is
> 
> $x="$y an example of the short form";
> 
> and
> 
> $x="{$y} is an example of the short form";
> 
>    You can get in trouble with the short form because it's greedy.  
> Imagine you're trying to make the name of a logfile
> 
> $logfile_name="$year_$month_$day_logfile.txt";
> 
>    PHP evaluates "$" expressions in a greedy manner,  so it will look up 
> the variables
> 
> $year_
> $month_
> $day_logfile
> 
> rather than
> 
> $year
> $month
> $day

Wouldn't I rather do the following anyway?
$logfile_name=$year."_".$month."_".$day."_logfile.txt";

I would never have gotten the idea to do this the way you described. 
Concatenation of the strings is IMHO way easier to comprehend, at least 
for me and maybe even for PHP.

David



More information about the talk mailing list