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

Function references and stateful cfcs?

New Here ,
Jun 08, 2009 Jun 08, 2009

Copy link to clipboard

Copied

Using 8.0.1

ok, i have a happy component (example4.cfc):

<cfcomponent output="false">
<cfscript>
  variables.txt = "un-init";
</cfscript>
<cffunction name="Init" access="public" returntype="example4" output="false">

  <cfscript>
  variables.txt = "init";
  </cfscript>
  <cfreturn this />
</cffunction>
<cffunction name="remoteEcho" access="remote" returntype="string" ExtDirect="true" output="false">
  <cfargument name="str" type="string" required="true" />

  <cfreturn str &  "[" & variables.txt & "]"/>
</cffunction>
</cfcomponent>

and I am trying to call a function reference like so:

<cfscript>
cfc = CreateObject('Component', 'Example4').Init();
method = cfc['RemoteEcho']; //<- try to create function reference
</cfscript>
<cfdump var="#cfc#">
<cfdump var="#method#">
<cfdump var="#cfc.remoteEcho('bobo')#"><!--- this works, naturally --->
<cfdump var="#method('bobo')#"><!--- failure here --->

The problem that I am running into is that it cannot find the variables.txt private member.

Element TXT is undefined in VARIABLES.

The direct call works fine, however the reference acts as if it's, i don't know, a regular UDF outside of a cfc?

Any help here, or will this just not work?

-Jim

TOPICS
Advanced techniques

Views

547

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
Enthusiast ,
Jun 08, 2009 Jun 08, 2009

Copy link to clipboard

Copied

LATEST

As far as I know it will not work if you're accessing private

variables because I seem to remember that the function reference is

not tied to the cfc instance.

Mack

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