• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

One CFFUNCTION calling another in same CFC - using "this" isn't working

LEGEND ,
May 20, 2015 May 20, 2015

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,

^_^

Views

899

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , May 21, 2015 May 21, 2015

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

Votes

Translate

Translate
Advocate ,
May 21, 2015 May 21, 2015

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 21, 2015 May 21, 2015

Copy link to clipboard

Copied

AH!  Thanks, haxtbh‌!  I didn't see that part (I am in a bit of a rush.)

V/r,

^_^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 21, 2015 May 21, 2015

Copy link to clipboard

Copied

LATEST

Follow-up question, if I may, :

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,

^_^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation