Reputation: 21
I have to use the reserved keyword "function" as variable name in ColdFusion. How can I do the same? I was trying with @ symbol but that didn't work. Any snippet will be helpful
Upvotes: 0
Views: 168
Reputation: 7833
You didn't mention the context of the variable, but here are some observations and possible workarounds:
<!--- works with ACF 10, 11, 2016, 2018 --->
<!--- works with Lucee 4+ --->
<cfset function = "function">
<cfoutput>#function#</cfoutput>
<!--- works everywhere --->
<cfset fieldName = "function">
<cfset variables[fieldName] = "function">
<cfoutput>variables[fieldName]</cfoutput>
<!--- works everywhere --->
<cffunction name="function">
<cfargument name="function">
<cfreturn arguments.function>
</cffunction>
<!--- works with ACF 10, 11, 2016 --->
<!--- doesn't work in Lucee at all --->
<cfoutput>#function("function")#</cfoutput>
<!--- works everywhere --->
<cfinvoke method="function" returnVariable="x">
<cfinvokeargument name="function" value="function">
</cfinvoke>
<cfoutput>#x#</cfoutput>
// doesn't work in ACF at all
// works with Lucee 5+
function = "function";
writeOutput(function);
// works everywhere
fieldName = "function";
variables[fieldName] = "function";
writeOutput(variables[fieldName]);
// doesn't work in ACF at all
// works with Lucee 5+
function function(function) {
return arguments.function;
}
// doesn't work in ACF at all
// doesn't work in Lucee at all
wrieOutput( function("function") );
// works in ACF
// doesn't work in Lucee due to a different bug
writeOutput( invoke("", "function", { "function": "function" }) );
In conclusion: Avoid using a reserved keyword! It's inconsistent and leads to preventable bugs.
Upvotes: 1