Skip to main content

Closures Do Not Work In Adobe ColdFusion Custom Tags

By Web Design2 min read

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:



	// 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;


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:



	cf_tag();

	writeDump( getMessage() );


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


https://bennadel.com/4821


Source link