Mysterious method added to your CFCs - where does it come from?

If you’ve been working with CFCs in ColdFusion 8, you may come across a mysterious method. Consider this screen shot from a CFC descriptor:

Notice the method, _cffunccfthread_cftest2ecfc6414264711. What the heck is that? As may be able to guess, it has something to do with threading. Check out the source for my CFC:

<cfcomponent output="false">

<cffunction name=”sayHi” access=”public” returnType=”string” output=”false”> <cfargument name=”name” type=”string” required=”false” default=”Nameless”> <cfthread name=”t”> <cfparam name=”request.x” default=”1”> <cfset request.x++> </cfthread> <cfreturn arguments.name> </cffunction>

</cfcomponent> </code>

See the cfthread call? Whenever threading is used inside a CFC method, a new method is added to the CFC metadata. You will also see this function if you call getComponentMetaData on the CFC. You can even call this method:

<cfset goo = createObject("component", "test")> <cfset goo._cffunccfthread_cftest2ecfc6414264711()>

When run, the code inside your cfthread tags are executed. Now I would not recommend actually doing that. As a related note - if you put a cfthread inside a normal CFM file and dump the variables scope, you will see a UDF with a similar name.

As a side note - I’ve always meant to play with the code that generates documentation for CFCs. In case you didn’t know, this is open source. It isn’t encrypted like the rest of the CFM files Adobe ships. It would be rather trivial to hide this from the documentation. I’d also like to add ways to execute methods by clicking on the event name or create a PDF version of the doc.

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Comments