Title:
Bug 79390:There is currently no way of dynamically invoking a CFC's method in CFScript
| View in TrackerStatus/Resolution/Reason: Closed/Fixed/
Reporter/Name(from Bugbase): Mark Mandel / Mark Mandel (mark.mandel)
Created: 08/11/2009
Components: Language, CFSCRIPT
Versions: 10.0
Failure Type: Unspecified
Found In Build/Fixed In Build: 0000 /
Priority/Frequency: Normal / Unknown
Locale/System: English / Platforms All
Vote Count: 26
Problem:
There is currently no way of dynamically invoking a CFC's method in CFScript.In tags, you are able to use <cfinvoke> to provide this functionality, but if you are in a Script based cfc this is not available.Railo provides a nice way of doing this, in the form of:foo = new Foo();foo[methodName]();Which I think would be a really nice addition to the ColdFusion language, but I would also be happy with a 'invoke' cfscript syntax as well.One thing to note - currently you can pass in the numerically keys arguments into <cfinvoke> as an argumentCollection and it works perfectly. Please ensure that this continues to work in CFScript, and therefore, this would work in the same way it would for <cfinvoke>args = {1="foo", 2="bar"};foo = new Foo();foo["myMethod"](argumentCollection=args);This is very important for usage with onMissingMethod.
-- Added as per discussion with Adam Cameron/Ray Camden --
The following syntax does seem to work but does not work correctly.
bar = foo[method];
bar();
This happens because the method execution holds the wrong context while executing. The issue is clearly demonstrated by the following example and it needs to be fixed.
C.cfc
{code:java}
component {
variables.where = "In the CFC!";
public function whereAmI(){
writeOutput(variables.where & "<br />");
hidden();
}
private function hidden(){
return;
}
}
{code}
test.cfm
{code:java}
<cfflush interval="1">
<cfscript>
variables.where = "In the calling code!";
o = new C();
o.WhereAmI();
methodName = "whereAmI";
methodToCall = o[methodName];
methodToCall();
</cfscript>
{code}
Error is mentioned in the error screen.
Method:
Result:
In the CFC!
In the calling code!
The web site you are accessing has experienced an unexpected error.
Please contact the website administrator.
The following information is meant for the website developer for debugging purposes.
Error Occurred While Processing Request
Variable HIDDEN is undefined.
The error occurred in C:\WebSites\scribble.local\cf\cfcs\pullOut\C.cfc: line 7
5 : public function whereAmI(){
6 : writeOutput(variables.where & "<br />");
7 : hidden();
8 : }
9 :
----------------------------- Additional Watson Details -----------------------------
Watson Bug ID: 3039641
External Customer Info:
External Company:
External Customer Name: Mark Mandel
External Customer Email: 3EA9517D445A9E8999201549
External Test Config: 08/11/2009
Attachments:
Comments: