Twitter: raymondcamden


Address: Lafayette, LA, USA

Ask a Jedi: cfinvoke versus createObject

04-05-2006 16,771 views ColdFusion

So I could have sworn I had blogged on this before, but I couldn't find it in my archives, so here goes. (And if I do start repeating myself, let me know folks!)

Is there a reason to favor cfinvoke over cfobject? Does cfinvoke clean up after itself faster?

Technically you are comparing apples and oranges. The cfobject tag (and createObject function) are meant to create an instance of a CFC. The cfinvoke tag runs a method on a CFC. You can use createObject to both create a CFC and run a method:

view plain print about
1<cfset foo = createObject("component", "president").init(42)>

But the same could be done with cfinvoke.

view plain print about
1<cfinvoke component="president" method="init" id="42" returnVariable="foo">

I think you will find it comes down to a style issue.