[nycphp-talk] Variables syntax
Aaron Fischer
agfische at email.smith.edu
Fri Oct 28 16:10:15 EDT 2005
Greetings listers,
A basic question I'm sure... (I have checked PHundamentals and did some
googling and manual searching and book skimming but haven't come up with
the answers I'm looking for.)
I have currently been setting variable like so:
Version A:
$print_first_name = "You said your first name is
{$_SESSION['first_name']}.";
At one time I think I had something like:
Version B:
$print_first_name = "You said your first_name is $_SESSION[first_name].";
This would yield the same result on my server, but I think version B is
incorrect and version A is correct. I am thinking that Version B is
incorrect as it is missing the single quotes around the var name, even
though it does render OK on my server, perhaps it would not in another
environment?
Then I also had something like:
Version C:
$print_first_name = "You said your first_name is " .
$_SESSION['first_name'] . ".";
Now I think Version C is technically correct, and the decision to use A
or C is based on personal preference.
Basically I'd like to establish a standard for myself and want to make
sure I'm understanding the usage and scenario's which can arise.
Is there a better alternative method?
Comments, thoughts, suggestions?
Thanks!
-Aaron
More information about the talk
mailing list