You do not want to get the method name, you want to get the actual method, for example, something like:
function getMethod(string method){ return variables[method]; }
A call that way:
theMethod = getMethod(variableHoldingMethodName); result = theMethod();
Unfortunately, you cannot just do this:
result = getMethod(variableFoldingMethodName)();
Or:
result = myObject[variableFoldingMethodName]();
Because the CF analyzer does not like double brackets or parentheses.
The caveat with the proposed method is that it pulls the method from CFC, so it will work in the context of the calling code, and not from the CFC instance. Depending on the code in the method, this may or may not matter.
Another alternative is to introduce a statically called INTO method into an object, for example:
dynamicName = "foo"; // for example myObject.staticName = myObject[dynamicName]; result = myObject.staticName(); // is actually calling foo();
source share