Is there any legitimate use for bare strings in PHP?

Posted by Robert on Stack Overflow See other posts from Stack Overflow or by Robert
Published on 2010-03-09T01:11:09Z Indexed on 2010/03/09 1:21 UTC
Read the original article Hit count: 404

Filed under:
|
|
|
|

This question got me thinking about bare strings.

When PHP sees a string that's not enclosed in quotes, it first checks to see if it's a constant. If not, it just assumes it's a string and goes on anyway. So for example if I have

echo $foo[bar];

If there's a constant called bar it uses that for the array key, but if not then it treats bar as a bare string, so it behaves just like

echo $foo["bar"];

This can cause all kinds of problems if at some future date a constant is added with the same name.

My question is, is there any situation in which it actually makes sense to use a bare string?

© Stack Overflow or respective owner

Related posts about php

Related posts about array