Re: Bizarre array key 'feature'?
| From: | Lars Torben Wilson | Date: | Thu, 09 Nov 2000 12:00:50 +0000 |
| Subject: | Re: Bizarre array key 'feature'? | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-37525@lists.php.net to get a copy of this message | ||
John Parker writes:
> Hi, all.
>
> Hmm.. bit of a strange one, this... Is 'default' considered a reserved word
> in the construction of muti-dimensional arrays?
'default' is a reserved word in PHP, yes: check out the switch
statement. If you turn up error_reporting(E_ALL) on the following
code, you'll get lots of this:
Warning: Use of undefined constant test - assumed 'test' in
/home/torben/public_html/phptest/__phplist.html on line 17
Warning: Use of undefined constant a - assumed 'a' in
/home/torben/public_html/phptest/__phplist.html on line 17
Warning: Use of undefined constant test - assumed 'test' in
/home/torben/public_html/phptest/__phplist.html on line 18
Warning: Use of undefined constant b - assumed 'b' in
/home/torben/public_html/phptest/__phplist.html on line 18
Quoting your array subscripts makes this go away, and tells the parser
you're using the string 'default' and not the reserved word.
> ie: The following code works.
>
> $ourArray[test][a] = true;
> $ourArray[test][b] = false;
> ...
>
> But the following fails (Parse error: parse error, expecting `']'') at the
> first line containing the 'default' key.
>
> $ourArray[default][a] = true;
> $ourArray[default][b] = false;
>
>
> Using PHP4.0.2 (yeah, I know I should probably upgrade).
>
> Thanks in advance,
> JP.
>
> ------------------------------------------------------------------
> John Parker email: jparker@itchannel.net
> Internet Project Manager/Software Engineer web:www.itchannel.net
> itCHANNEL International Ltd. tel: +44 (0) 1202 291939
--
+----------------------------------------------------------------+
|Torben Wilson <torben@php.net> Netmill iTech|
|http://www.coastnet.com/~torben http://www.netmill.fi|
|Ph: 1 250 383-9735 torben@netmill.fi|
+----------------------------------------------------------------+