Closures Do Not Work In Adobe ColdFusion Custom Tags
This is a quick post about a bug that I ran into this morning. Closures, which bind a function to its lexical scoping, do not work inside Adobe ColdFusion custom tags. Meaning, a closure defined inside a custom tag does not retain scoping to the custom tag page context when passed out of scope (such as into the caller
context).
Aside: custom tag closures do work in Lucee CFML — this is an Adobe ColdFusion (ACF) specific bug.
To demonstrate, let's create a simple ColdFusion custom tag that defines a closure that closes over the custom-tag-local variable, message
. Then, we'll pass this closure out of context using the caller
tunnel:
<cfscript>
// The variable that we're CLOSING OVER.
message = "Hello from closed-over Custom Tag!";
// The closure that accesses the closed-over variable.
getClosedOverVariable = () => message;
// Passing the closure out of context.
caller.getMessage = getClosedOverVariable;
</cfscript>
Because this was defined as a closure, the getClosedOverVariable()
function should retain access to the message
variable. However, when we try to invoke this from the calling context:
<cfscript>
cf_tag();
writeDump( getMessage() );
</cfscript>
... we get an error:
Variable
MESSAGE
is undefined.
This is true even in Adobe ColdFusion 2025. I will file a bug and post it in the comments down below.
Want to use code from this post? Check out the license.
Reader Comments
I filed bug CF-4227145 in the Adobe Tracker.
Post A Comment — ❤️ I'd Love To Hear From You! ❤️
Post a Comment →