Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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