Re: Using ' to access session variables?
| From: | Michal Migurski | Date: | Fri, 16 Apr 2004 16:39:38 +0000 |
| Subject: | Re: Using ' to access session variables? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-183643@lists.php.net to get a copy of this message | ||
>Whats the difference between $_SESSION[foo] and $_SESSION['foo'] I have
>been using the 's but they seem to be unecessary?
Use the single-quotes -- array references often work without them, but the
potential for conflict with constants and future PHP incompatibility is a
possibility. If you (or PHP) had a constant foo defined, it would behave
unexpectedly.
>I run into trouble if I try something like:
>$query = " select * from table where (test.id = '$_SESSION['foo']')
>";
>but the following works:
>$query = " select * from table where (test.id = '$_SESSION[foo]') ";
http://www.php.net/manual/en/language.types.string.php#language.types.string.parsing
// Works but note that this works differently outside string-quotes
echo "A banana is $fruits[banana].";
// Works
echo "A banana is {$fruits['banana']}.";
// Works but PHP looks for a constant named banana first
// as described below.
echo "A banana is {$fruits[banana]}.";
// Won't work, use braces. This results in a parse error.
echo "A banana is $fruits['banana'].";
---------------------------------------------------------------------
michal migurski- contact info and pgp key:
sf/ca http://mike.teczno.com/contact.html