Re: Using ' to access session variables?
| From: | Richard Harb | Date: | Fri, 16 Apr 2004 16:48:39 +0000 |
| Subject: | Re: Using ' to access session variables? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-183645@lists.php.net to get a copy of this message | ||
If used outside any strings (like in your $query example)
$_SESSION[foo] -- here foo technically is a constant
and php ought to produce a notice
$_SESSION['foo'] -- is the correct way as there is no doubt that foo
is a string
When used inside a string the rules are slightly altered
@see http://www.php.net/manual/en/language.types.array.php
section Array do's and don'ts
Richard
Friday, April 16, 2004, 6:32:11 PM, you wrote:
> Whats the difference between $_SESSION[foo] and $_SESSION['foo'] I have been
> using the 's but they seem to be unecessary?
> 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]') ";
> I know there is some way to properly escape characters but is there any
> reason why I shouldn't just omit the 's?
> Thanks!