Skip to main content
Participant
May 13, 2010
Question

List of functions in CFC

  • May 13, 2010
  • 1 reply
  • 454 views

Hi,

I need to get a list of functions inside a CFC and then do 'something with that list'. I know I can dump the visual output after I instantiate the object, but I can't seem to access the 'methods' key as a structure/array etc. Anyone know how to interpret the contents of the object (like looping through it for example)?

Cheers
John

    This topic has been closed for replies.

    1 reply

    Inspiring
    May 13, 2010

    There are a couple of approaches.  All the methods within a CFC are in its THIS (public, remote, package) or VARIABLES (private) scope, so one could iterate over those and check each key as to whether it passes isCustomFunction() (http://livedocs.adobe.com/coldfusion/8/htmldocs/functions_in-k_10.html).

    But better would be to use getMetaData() (http://livedocs.adobe.com/coldfusion/8/htmldocs/functions_e-g_50.html) on an instance of the CFC, or - on CF9 -  getComponentMetaData() (http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7dd9.html), if you don't want to first instantiate the CFC.

    --
    Adam

    Participant
    May 13, 2010

    Perfect!

    I am going to use the getMetaData(). Out of interest though how would I iterate over the methods in THIS? I cant get at the methods [struct?] but I can obviously see it in a dump...

    Thanks

    John

    Inspiring
    May 13, 2010

    From within the CFC code:

    <cfloop item="sVariable" collection="#this#">

         <cfif isCustomFunction(this[sVariable])>

    From the calling code:

    <cfloop item="sVariable" collection="#objName#">

          <cfif isCustomFunction(objName[sVariable])>

    Have never had call to do the latter, but it should work (?)

    --

    Adam