Specifications

Optional values do not all need to be providedwe can provide some and ignore some.
Parameters will be assigned from left to right.
Keep in mind that you cannot leave out one optional parameter but include a later listed one.
In this example, if you want to pass a value for cellspacing, you will have to pass one for
cellpadding as well. This is a common cause of programming errors. It is also the reason
that optional parameters are specified last in any list of parameters.
The following function call:
create_table2($my_array, 3);
is perfectly legal, and will result in $border being set to 3 and $cellpadding and
$cellspacing being set to their defaults.
Scope
You might have noticed that when we needed to use variables inside a required or included
file, we simply declared them in the script before the require() or include() statement, but
when using a function, we explicitly passed those variables into the function. This is partly
because no mechanism exists for explicitly passing variables to a required or included file, and
partly because variable scope behaves differently for functions.
A variables scope controls where that variable is visible and useable. Different programming
languages have different rules that set the scope of variables. PHP has fairly simple rules:
Variables declared inside a function are in scope from the statement in which they are
declared to the closing brace at the end of the function. This is called function scope.
These variables are called local variables.
Variables declared outside of functions are in scope from the statement in which they are
declared to the end of the file, but not inside functions. This is called global scope.
These variables are called global variables.
Using require() and include() statements does not affect scope. If the statement is
used within a function, function scope applies. If it is not inside a function, global scope
applies.
The keyword global can be used to manually specify that a variable defined or used
within a function will have global scope.
Variables can be manually deleted by calling unset($variable_name). A variable is no
longer in scope if it has been unset.
The following examples might help to clarify things.
Using PHP
P
ART I
136
07 7842 CH05 3/6/01 3:35 PM Page 136