User Guide

Table Of Contents
182 Chapter 9: Writing and Calling User-Defined Functions
The resulting Arguments scope looks like the following:
In this example, the following functions return the value 2 because there are two defined
arguments:
ArrayLen(Arguments)
StructCount(Arguments)
However, the following tests return the value False, because the contents of the second element in
the Arguments scope is undefined.
Isdefined("Arguments.Arg2")
testArg2 = Arguments[2]>
Isdefined("testArg2")
Note: The
IsDefined function does not test the existence of array elements. Instead, put any code
that might try to access an undefined array element in a try block and use a catch block to handle
exceptions that arise if elements do not exist.
Using the Arguments scope as an array
The following rules apply to referencing Arguments scope as an array:
If you call the function using unnamed arguments, the array index is the position of the
argument in the function call.
If you use names to pass the arguments, the array indexes correspond to the order in which the
arguments are declared in the function definition.
If you use names to pass arguments, and do not pass all the arguments defined in the function,
the Arguments array has an empty entry at the index corresponding to the argument that was
not passed. This rule applies only to functions created using the
cffunction tag.
If you use a name to pass an optional argument that is not declared in the function definition,
the array index of the argument is the sum of the following:
a
The number of arguments defined with names in the function.
b
The position of the optional argument among the arguments passed in that do not have
names defined in the function.
However, using argument names in this manner is not good programming practice because
you cannot ensure that you always use the same optional argument names when calling the
function.
To demonstrate these rules, define a simple function that displays the contents of its Arguments
array and call the function with various argument combinations, as shown in the following
example:
<cffunction name="TestFunction" >
<cfargument name="Arg1">
As an array As a structure
Entry Value Entry Value
11 Arg11
2 undefined Arg2 undefined