Next Previous Contents

6. Strings

6.1 Single- or Double-quoted

Everytime you need to use a string consider if you really need double-quoted string. If you do not want to expand variable names or use special escape characters, you are encouraged to use single-quoted strings. The reason is obvious - use of double-quoted strings is more time consuming in the runtime.

'foo bar'       // good
"foo {$bar}"   // good
"foo\nbar"     // good
"foo bar"      // bad

6.2 Expanding Variables

Variables to be expanded in double-quoted strings should be enclosed with curly braces. This helps to avoid problems with confusing constructions. For example

"{$foo}bar"    // good

has completely different meaning than:

"$foobar"     // bad

On the other hand, it is the only way to use array indices directly in strings:

"{$foo['bar']}"    // good
"$foo['bar']"      // bad


Next Previous Contents