Skip to main content
Ben Nadel at NCDevCon 2011 (Raleigh, NC) with: Matthew Williams
Ben Nadel at NCDevCon 2011 (Raleigh, NC) with: Matthew Williams

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>

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

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

Post a Comment

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