![MACROMEDIA COLDFUSION 5-DEVELOPING Develop Manual Download Page 272](http://html1.mh-extra.com/html/macromedia/coldfusion-5-developing/coldfusion-5-developing_develop-manual_3293641272.webp)
252
Chapter 13 Extending ColdFusion Pages with CFML Scripting
Each function has a built-in
Arguments
array containing all arguments passed to the
function: the required arguments specified by the function parameters followed by
any additional arguments included in the function call.
The function can determine the number of arguments passed to it by using the
ColdFusion function call
ArrayLen(Arguments)
.
The function must retrieve the optional arguments by using the
Arguments
array. For
example, if the following function:
function MyFunction(MyArg1, MyArg2)
has three optional arguments, you can refer to the first two, required, arguments as
MyArg1
and
MyArg2
or as
Arguments[1]
and
Arguments[2]
. You must refer to the
third and fourth and fifth, optional, arguments as
Arguments[3]
,
Arguments[4],
and
Arguments[5].
However, you must be careful if you mix references to the same argument using both
its parameter name and its place in the
Arguments
array. Mixing is fine if all you do is
read the argument. If you write the argument, you should consistently use either the
parameter name or the Arguments array.
Passing arguments
ColdFusion passes arrays and simple data types including integers, strings, and time
and date values into the function by value. It passes queries and structures into the
function by reference. As a result, if you change the value of a query or structure
argument variable in the function, it changes the value of the variable that the calling
page used in calling the function. However, if you change the value of an array or
string argument variable in the function, it does not change the value of the string
variable in the calling page.
Using variables
A function can access all variables that are available in the calling page. In addition,
the function has its own private scope that contains the function parameters, the
Arguments
array, and the
var
-declared variables. This scope is only accessible inside
the current instance of the function. As soon as the function exits, all the variables
are removed.
A function can use and change any variable that is available in the calling page,
including variables in the caller’s Variables (local) scope, as if the function were part
of the calling page. For example, if you know that the calling page has a local variable
called Customer_name (and there is no
var
variable named Customer_name) the
function can read and change the variable by referring to it as "Customer_name" or
(using better coding practice) "Variables.Customer_name".
Similarly, you can create a local variable inside a function and then refer to it
anywhere in the calling page after the function call. You cannot refer to the variable
before you call the function.
Because function
var
variables do not take a scope identifier and exist only while the
function executes, function variable names can be independent of variable names
Summary of Contents for COLDFUSION 5-DEVELOPING
Page 1: ...Macromedia Incorporated Developing ColdFusion Applications MacroMedia ColdFusion 5 ...
Page 58: ...38 Chapter 3 Querying a Database ...
Page 134: ...114 Chapter 7 Updating Your Database ...
Page 210: ...190 Chapter 10 Reusing Code ...
Page 232: ...212 Chapter 11 Preventing and Handling Errors ...
Page 238: ...218 Chapter 12 Using the Application Framework ...
Page 262: ...242 Chapter 12 Using the Application Framework ...
Page 278: ...258 Chapter 13 Extending ColdFusion Pages with CFML Scripting ...
Page 320: ...300 Chapter 15 Indexing and Searching Data ...
Page 336: ...316 Chapter 16 Sending and Receiving E mail ...
Page 374: ...354 Chapter 18 Interacting with Remote Servers ...