Skip to content

Instantly share code, notes, and snippets.

@bennadel
Created March 25, 2014 11:42
Show Gist options
  • Save bennadel/9760098 to your computer and use it in GitHub Desktop.
Save bennadel/9760098 to your computer and use it in GitHub Desktop.
ColdFusion Ordered ArgumentCollection Behavior Depends On ColdFusion Version And Invocation Context
<cffunction
name="echoArguments"
access="public"
returntype="any"
output="false"
hint="I simply return the arguments collection to demonstrate their structure to the calling context.">
<!---
NOTE: In this demo, we are not going to define any
CFArgument tags - we are just going to let the invocation
context define the arguments.
--->
<!--- Return the arguments. --->
<cfreturn arguments />
</cffunction>
<h1>
CF8 - No CFArgument Tags
</h1>
<!---
Create the argument collection at a struct using "ordered" keys.
Since the Arguments of a function can be addressed as both named
and ordered arguments, this allows for some awesome flexability.
--->
<cfset myArguments = {} />
<cfset myArguments[ 1 ] = "Katie (1st Arg)" />
<cfset myArguments[ 2 ] = "Colleen (2nd Arg)" />
<!--- ----------------------------------------------------- --->
<!--- ----------------------------------------------------- --->
<!---
Now, we are going to try and echo the argument collection we
just created using the CFInvoke tag.
--->
<h2>
CFInvoke Tag Invocation
</h2>
<!--- Pass in the arguments collection. --->
<cfinvoke
returnvariable="result"
method="echoArguments"
argumentcollection="#myArguments#"
/>
<!--- Output the results. --->
<cfdump
var="#result#"
label="CFInvoke Invocation"
/>
<!--- ----------------------------------------------------- --->
<!--- ----------------------------------------------------- --->
<!---
Now, we are going to try and echo the argument collection using
standard method invocation and the argumentCollection command.
--->
<h2>
Method Invocation
</h2>
<!--- Pass in the arguments collection. --->
<cfset result = echoArguments( argumentCollection = myArguments ) />
<!--- Output the results. --->
<cfdump
var="#result#"
label="Method Invocation"
/>
<cffunction
name="echoArguments"
access="public"
returntype="any"
output="false"
hint="I simply return the arguments collection to demonstrate their structure to the calling context.">
<!--- Define arguments. --->
<cfargument name="girl1" />
<cfargument name="girl2" />
<!--- Return the arguments. --->
<cfreturn arguments />
</cffunction>
<cffunction
name="echoArguments"
access="public"
returntype="any"
output="false"
hint="I simply return the arguments collection to demonstrate their structure to the calling context.">
<!---
NOTE: In this demo, we are not going to define any
CFArgument tags - we are just going to let the invocation
context define the arguments.
--->
<!--- Return the arguments. --->
<cfreturn arguments />
</cffunction>
<h1>
CF9 (No Updater) - No CFArgument Tags
</h1>
<!---
Create the argument collection at a struct using "ordered" keys.
Since the Arguments of a function can be addressed as both named
and ordered arguments, this allows for some awesome flexability.
--->
<cfset myArguments = {} />
<cfset myArguments[ 1 ] = "Katie (1st Arg)" />
<cfset myArguments[ 2 ] = "Colleen (2nd Arg)" />
<!--- ----------------------------------------------------- --->
<!--- ----------------------------------------------------- --->
<!---
Now, we are going to try and echo the argument collection we
just created using the CFInvoke tag.
--->
<h2>
CFInvoke Tag Invocation
</h2>
<!--- Pass in the arguments collection. --->
<cfinvoke
returnvariable="result"
method="echoArguments"
argumentcollection="#myArguments#"
/>
<!--- Output the results. --->
<cfdump
var="#result#"
label="CFInvoke Invocation"
/>
<!--- ----------------------------------------------------- --->
<!--- ----------------------------------------------------- --->
<!---
Now, we are going to try and echo the argument collection using
standard method invocation and the argumentCollection command.
--->
<h2>
Method Invocation
</h2>
<!--- Pass in the arguments collection. --->
<cfset result = echoArguments( argumentCollection = myArguments ) />
<!--- Output the results. --->
<cfdump
var="#result#"
label="Method Invocation"
/>
<cffunction
name="echoArguments"
access="public"
returntype="any"
output="false"
hint="I simply return the arguments collection to demonstrate their structure to the calling context.">
<!--- Define arguments. --->
<cfargument name="girl1" />
<cfargument name="girl2" />
<!--- Return the arguments. --->
<cfreturn arguments />
</cffunction>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment