Created
March 25, 2014 11:42
-
-
Save bennadel/9760098 to your computer and use it in GitHub Desktop.
ColdFusion Ordered ArgumentCollection Behavior Depends On ColdFusion Version And Invocation Context
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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" | |
/> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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" | |
/> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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