Skip to main content
Ben Nadel at CF Summit West 2024 (Las Vegas) with: Austin Shelton
Ben Nadel at CF Summit West 2024 (Las Vegas) with: Austin Shelton

Closures Do Not Work In Adobe ColdFusion Custom Tags

By
Published in Comments (1)

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>
view raw Tag.cfm hosted with ❤ by GitHub

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>
view raw test.cfm hosted with ❤ by GitHub

... 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

Post A Comment — I'd Love To Hear From You!

Markdown formatting: Basic formatting is supported: bold, italic, blockquotes, lists, fenced code-blocks. Read more about markdown syntax »
Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.
Cancel
I believe in love. I believe in compassion. I believe in human rights. I believe that we can afford to give more of these gifts to the world around us because it costs us nothing to be decent and kind and understanding. And, I want you to know that when you land on this site, you are accepted for who you are, no matter how you identify, what truths you live, or whatever kind of goofy shit makes you feel alive! Rock on with your bad self!
Ben Nadel