Copy link to clipboard
Copied
Hello, all,
I've got a CFC (let's call it test.cfc) that is supposed to handle a lot of internal calls to other CFFUNCTIONs.
I had read that using "this.functionName(args);" should work.
However, for some reason it isn't. I still have to use "components.compName().functionName(args);" for it to work. Pseudo-code:
<cffunction name="functionA" access="private" output="no" returntype="any">
<cfquery name="getThese" datasource="#application.thisDSN#">
SELECT * FROM tableA ORDER BY ID
</cfquery>
<cfreturn getThese />
</cffunction>
and
<cffunction name="functionB" access="private" output="yes" returntype="void">
<cfset tmp = this.functionA() /><cfoutput>#tmp#</cfoutput>
</cffunction>
This produces the error: Ensure that the name is correct and that the component or interface exists.
But the following works just fine:
<cffunction name="functionB" access="private" output="yes" returntype="void">
<cfset tmp = components.test().functionA() /><cfoutput>#tmp#</cfoutput>
</cffunction>
Any suggestions as to why "new this.test().functionA();" doesn't work?
V/r,
^_^
The this scope is a public scope. You will need to change your functions to be access="public"
Note: The This scope identifier works like the This keyword in JavaScript and ActionScript. CFCs do not follow the Java class model, and the This keyword behaves differently in ColdFusion than in Java. In Java, This is a private scope, whereas in ColdFusion, it is a public scope.
CFC variables and scope - ColdFusion, English documentation - Adobe Learning Resources
Copy link to clipboard
Copied
The this scope is a public scope. You will need to change your functions to be access="public"
Note: The This scope identifier works like the This keyword in JavaScript and ActionScript. CFCs do not follow the Java class model, and the This keyword behaves differently in ColdFusion than in Java. In Java, This is a private scope, whereas in ColdFusion, it is a public scope.
CFC variables and scope - ColdFusion, English documentation - Adobe Learning Resources
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Follow-up question, if I may, haxtbh:
I tried to set some of the functions to private and call them via "varName = new components.componentName().methodName(argumentCollection = variables.structName);".. but keep getting an error message that "The method methodName was not found in componentName()." If I'm explicitly calling through the component mapping, shouldn't that work, even though the component is private AND resides in the same CFC from whence I am calling the method?
V/r,
^_^