IMO, CFINVOKE is both much cleaner code and probably more efficient. Evaluate() often has non-trivial overhead, relatively speaking, though that is a trivial concern in most cases -- the bigger issue is code readability. CFINVOKE is semantically much more descriptive about what your code is doing, and any developer who has to read your code later will thank you for not obfuscating matters.

You can reuse an object instance in CFINVOKE by passing it in as a variable, which captures the one "advantage" you are identifying:

<cfinvoke component="#yourInstance#" ...>





Cody Caughlan wrote:
Hi-

Is it better to use cfinvoke to dynamically call a method on a CFC or to use
the Evaluate() function?

E.g.

Approach A:

<cfset obj = CreateObject('component', 'foobar').init()>
<cfset FunctioName = "getName">
<cfset foo = Evaluate("obj.#FunctionName#()")>

-- OR --

Approach B:

<cfset FunctioName = "getName">
<cfinvoke component="foobar" method=#FunctionName# returnvariable="foo" />

Other than that Approach A takes an extra line to instantiate the object, is
it better overall to use cfinvoke? One advantage that Approach A has for our
needs is that we are potentially running this in a loop, so we can create
the object once and then put it in a cache struct and re-use it in a
subsequent loop call, whereas cfinvoke just calls it in a one-off fashion.

Any ideas? (Dont say use ColdSpring...)

Thanks
/Cody




----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to 
[email protected] with the words 'unsubscribe cfcdev' as the subject of the 
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting 
(www.cfxhosting.com).

An archive of the CFCDev list is available at 
www.mail-archive.com/[email protected]







----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to 
[email protected] with the words 'unsubscribe cfcdev' as the subject of the 
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting 
(www.cfxhosting.com).

An archive of the CFCDev list is available at 
www.mail-archive.com/[email protected]


Reply via email to