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

(singke) #1

$ (^) Reference a Variable
& (^) Reference Variable Storage
-> (^) Reference a Class Method or Property
=> (^) Set Argument Default or Assign Array Element Index
@ (^) Suppress Error Messages
? (^) Tertiary Conditional Expression
{} (^) Variable Embedded in a String
When a function is called with an argument, the value of the argument is passed to the
function and put into the special argument variable in the function declaration. If a
variable is used inside a function call, only the value of the variable is sent to the
function. If you choose to change the value of an argument, the original variable will be
unchanged.
However, if you put an ampersand before the dollar sign in a function declaration, the
function will expect a reference to a variable. Inside the function the argument acts like
an alias to the supplied variable; any change to the argument changes the variable named
in the function call. This behavior is discussed and demonstrated in Chapter 4.
Outside of functions, the ampersand allows you to make more than one variable point to
the same area of memory. This is like making an alias. Operations on either variable will
change the underlying memory, as demonstrated in Listing 2.9.
Listing 2.8 The Concatenation Operator
<?
$Query = "SELECT LastName, FirstName ".
"FROM Clients ".
"WHERE Disposition = 'Pleasant' ".
"ORDER BY LastName ";
print($Query);
?>
Listing 2.9 The Reference Operator

Free download pdf