faqts : Computers : Programming : Languages : PHP : kms : General

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

3 of 10 people (30%) answered Yes
Recently 2 of 9 people (22%) answered Yes

Entry

Can I reference arrays without quotes?
Does PHP support the use of bare words?

Jul 8th, 1999 21:50
Nathan Wallace,


Bare words (ie: words used in code without quotes) will work as long as
none of the bare words collides with something else. This is similar to
the 'bare word' support in perl.

The use of bare words is not a recommended programming practice in PHP. 
It is an implementation side-effect that non-reserved words work as
strings even though they are not quoted.  This behaviour should not be
relied upon to work in future versions.

Example:

    $a["one"] = 1;
    $a["two"] = 2;

Can also be written in the bare words form as:

    $a[one] = 1;
    $a[two] = 2;

You can also use bare words any time that a simple string constant is
required.  For example:

    $foo = bar;

will work, but

    $foo = bar none;

won't work.  In the second case the space (or any character other than a
simple letter or number) means that PHP cannot parse the bare word so
quotes are required:

    $foo = 'bar none';