Specifications

One important difference between constants and variables is that when you refer to a constant,
it does not have a dollar sign in front of it. If you want to use the value of a constant, use its
name only. For example, to use one of the constants we have just created, we could type:
echo TIREPRICE;
As well as the constants you define, PHP sets a large number of its own. An easy way to get an
overview of these is to run the phpinfo() command:
phpinfo();
This will provide a list of PHPs predefined variables and constants, among other useful infor-
mation. We will discuss some of these as we go along.
Variable Scope
The term scope refers to the places within a script where a particular variable is visible. The
three basic types of scope in PHP are as follows:
Global variables declared in a script are visible throughout that script, but not inside
functions.
Variables used inside functions are local to the function.
Variables used inside functions that are declared as global refer to the global variable of
the same name.
We will cover scope in more detail when we discuss functions. For the time being, all the vari-
ables we use will be global by default.
Operators
Operators are symbols that you can use to manipulate values and variables by performing an
operation on them. Well need to use some of these operators to work out the totals and tax on
the customers order.
Weve already mentioned two operators: the assignment operator, =, and ., the string concate-
nation operator. Now well look at the complete list.
In general, operators can take one, two, or three arguments, with the majority taking two. For
example, the assignment operator takes twothe storage location on the left-hand side of
the = symbol, and an expression on the right-hand side. These arguments are called operands,
that is, the things that are being operated upon.
PHP Crash Course
C
HAPTER 1
1
PHP CRASH
COURSE
25
03 7842 CH01 3/6/01 3:39 PM Page 25