Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 168

Developing applications
Hide thumbs Also See for 38043740 - ColdFusion Standard - Mac:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Building Blocks of ColdFusion Applications
• 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:
• The number of arguments defined with names in the function.
• 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 the following example shows:
<cffunction name="TestFunction" >
<cfargument name="Arg1">
<cfargument name="Arg2">
<cfloop index="i" from="1" to="#ArrayLen(Arguments)#">
<cfoutput>Argument #i#: #Arguments[i]#<br></cfoutput>
</cfloop>
</cffunction>
<strong>One Unnamed argument</strong><br>
<cfset TestFunction(1)>
<strong>Two Unnamed arguments</strong><br>
<cfset TestFunction(1, 2)>
<strong>Three Unnamed arguments</strong><br>
<cfset TestFunction(1, 2, 3)>
<strong>Arg1:</strong><br>
<cfset TestFunction(Arg1=8)>
<strong>Arg2:</strong><br>
<cfset TestFunction(Arg2=9)>
<strong>Arg1=8, Arg2=9:</strong><br>
<cfset TestFunction(Arg1=8, Arg2=9)>
<strong>Arg2=6, Arg1=7</strong><br>
<cfset TestFunction(Arg2=6, Arg1=7)>
<strong>Arg1=8, Arg2=9, Arg3=10:</strong><br>
<cfset TestFunction(Arg1=8, Arg2=9, Arg3=10)>
<strong>Arg2=6, Arg3=99, Arg1=7</strong><br>
<cfset TestFunction(Arg2=6, Arg3=99, Arg1=7)>
Note: Although you can use the Arguments scope as an array, the
and the
tag displays the scope as a structure.
cfdump
Using the Arguments scope as a structure
The following rule applies when referencing Arguments scope as a structure:
• Use the argument names as structure keys. For example, if your function definition includes a Principal argument,
reference the argument as Arguments.Principal.
The following rules are also true, but avoid writing code that uses them. To ensure program clarity, only use the
Arguments structure for arguments that you name in the function definition. Use the Arguments scope as an array
for optional arguments that you do not declare in the function definition.
IsArray(Arguments)
Last updated 1/20/2012
function always returns
false
163

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents