cfinvoke can only be used in tags.
createObject can be used in both tags and cfscript and tends to be slightly thinner / easier to read IMO.
Until recently, I avoided using cfinvoke because I found it to be cumbersome, but you can dynamically iterate over methods inside CFC about it. In createobject you cannot.
So, if, for example, I have a CFC that has methods - method1, method2, method3, method4. I can go through them like this: -
<cfloop from="1" to="4" index="element"> <cfif structKeyExists(this,'getMethod#element#')> <cfinvoke component="#this#" method="getLine#local.element#" returnVariable="methodValue"></cfinvoke> <cfset arrayAppend(myArray,methodValue) /> </cfif>
-
Another thing to note is that some hosts share the lock on createobject. Mostly because of the access it provides for underlining Java.
James buckingham
source share