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
_______________________________________________
New York PHP Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

NYPHPCon 2006 Presentations Online
http://www.nyphpcon.com

Show Your Participation in New York PHP
http://www.nyphp.org/show_participation.php

Reply via email to