Re: GLOBAL[as]
| From: | Lars Torben Wilson | Date: | Thu, 14 Sep 2000 10:12:10 +0000 |
| Subject: | Re: GLOBAL[as] | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-16747@lists.php.net to get a copy of this message | ||
meling writes:
> While helping a developer debugging a code today,
> we found that having a line like this:
>
> $ans = GLOBALS[as]
>
> will give a parse error (expecting "]"). However, when
> the same code is run on PHP 3.0.7 (we have a development
> server that has not been upgraded yet - my bad) it worked.
>
> Is as] a reserved word in PHP 4.0.0? Or a bug. When I tested
> the same line on PHP 4.0.2, it worked...
>
> -- mel
> Meling Mudin < meling at myweb.com.my >
> System Administrator, TecnoChannel Technologies.
> 03-460 9282 ext 222 / 012-663 4327
> "God is real unless declared integer."
It's part of the foreach() construct. But anyway, you should always
quote string indices in associative arrays--to prevent exactly this
sort of thing.
For instance, $some_array[default]; will not work: 'default' is a
keyword in PHP. However, $some_array['default'] will work, since
you've just specified that you want to use a string.
If you turn error reporting all the way up when you are developing,
you'll have an easier time avoiding this type of problem.
--
+----------------------------------------------------------------+
|Torben Wilson <torben@php.net> Netmill iTech|
|http://www.coastnet.com/~torben http://www.netmill.fi|
|Ph: 1 250 383-9735 torben@netmill.fi|
+----------------------------------------------------------------+