Specifications

You can use as many sets of parentheses as you like in an expression. The innermost set of
parentheses will be evaluated first.
Variable Functions
Before we leave the world of variables and operators, well take a look at PHPs variable func-
tions. These are a library of functions that enable us to manipulate and test variables in differ-
ent ways.
Testing and Setting Variable Types
Most of these functions have to do with testing the type of a function.
The two most general are gettype() and settype(). These have the following function proto-
types; that is, this is what arguments expect and what they return.
string gettype(mixed var);
int settype(string var, string type);
To use gettype(), we pass it a variable. It will determine the type and return a string contain-
ing the type name, or “unknown type” if it is not one of the standard types; that is, integer,
double, string, array, or object.
To use settype(), we pass it a variable that we would like to change the type of, and a string
containing the new type for that variable from the previous list.
We can use these as follows:
$a = 56;
echo gettype($a).”<br>”;
settype($a, “double”);
echo gettype($a).”<br>”;
When gettype() is called the first time, the type of $a is integer. After the call to settype(),
the type will be changed to double.
PHP also provides some type-specific, type-testing functions. Each of these takes a variable as
argument and returns either true or false. The functions are
is_array()
is_double(), is_float(), is_real() (All the same function)
is_long(), is_int(), is_integer() (All the same function)
is_string()
is_object()
Using PHP
P
ART I
36
03 7842 CH01 3/6/01 3:39 PM Page 36