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

that you probably want.

$logfile_name="{$year}_{$month}_{$day}_logfile.txt";

gets the desired effect. The long form also lets you do cool things with arrays and object, like

"{$my_array[$index]}"
"{$my_array["i_can_really_use_quotes_to_have_a_string_here"]}"
"{$object->special_property}"



_______________________________________________
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