Skip to main content
Participating Frequently
June 8, 2009
Question

Function references and stateful cfcs?

  • June 8, 2009
  • 1 reply
  • 594 views

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

This topic has been closed for replies.

1 reply

Participating Frequently
June 8, 2009

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