Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites

(singke) #1

The dollar-sign operator may operate on the result of another dollar-sign operator. In the
simplest case a variable holds the name of another variable. This is shown in Listing 2.10


Note that { and } is used for grouping as the parentheses are used for numbers. This
eliminates the ambiguity that can arise when referencing arrays. It also allows you to
specify elements of multidimensional arrays inside strings. But even when not strictly
necessary, it's a good idea to use curly braces as I have in Listing 2.10. It's clear that I
mean to use a variable to name another variable here.


The dollar-sign operator is unique because it is executed when placed inside double
quotes. This allows you to avoid the extra code needed to break from a string to insert the
value of a variable. But dollar signs inside double quotes do not behave exactly like
dollar signs outside double quotes. When two or more dollar signs appear together, all but
the last will be treated as any other character with no meaning. To use one variable to
name another, use curly braces. Listing 2.10 demonstrates the subtleties of this
functionality.


The -> operator is used strictly to reference either methods or properties of classes, which
are discussed in Chapter 6. The left-hand side of the operator is the name of an

Free download pdf