Re: accessing $GLOBALS values
| From: | Ivo Fokkema | Date: | Tue, 02 Sep 2003 07:20:40 +0000 |
| Subject: | Re: accessing $GLOBALS values | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-161428@lists.php.net to get a copy of this message | ||
"Dennis Gearon" <gearond@fireserve.net> wrote in message
news:3F542A6E.5090007@fireserve.net...
[snip]
> One thing I'm a little confused about is the usage of $GLOBALS array, in
> this manner:
>
> $GLOBALS[SOME_NAME].
>
> I thought that it should be:
>
> $GLOBALS['SOME_NAME'].
Hi,
You should use quotes to tell PHP it's a string you're using as a key of
$GLOBALS. However, when not using quotes PHP will first look for a constant
with that name. If PHP can't find any, it will assume it's a string. So not
using quotes might lead to problems when you use the name of a constant as a
key.
I hope this is clear, more info can be found at
http://www.php.net/manual/en/language.types.array.php
and scroll down to
'Array do's and don'ts' -> 'Why is $foo[bar] wrong?'
HTH,
Ivo Fokkema