Tom Muck

Alpha Dog Blues Band
Home page
All articles
All Extensions | Extension News | Extension FAQs | Customer Login
Books authored or co-authored by Tom Muck
Extensions, books, and other products | Customer Login
Your current cart contents
Tom-Muck.com Blog | CMXTraneous Blog | Flash Remoting Blog
About the site

Blog

Tom Muck's Blog: CFC Instance copies failTom Muck's Blog

News and Views

CFC Instance copies fail

Saturday, March 11, 2006 7:14:50 PM

I discovered an interesting thing about CFCs that I did not know, and the cause of an error message I have been having problems resolving. I have several CFCs that I use in session or application variables. I made the mistake of using StructCopy to put an instance of the application variable instance into request scope (Duplicate does not seem work on CFCs). Most things seemed to work perfectly, but when attempting to use a function within the CFC, there did not seem to be a way to do it:

<cfcomponent name="test">
  <cffunction name="foo">
    <cfreturn "blah"/>
  </cffunction>
  <cffunction name="callFoo">
    <cfset var temp = foo()>
    <cfreturn temp />
  </cffunction>
</cfcomponent>

Because callFoo() calls foo() within the cfc, it fails. This works:

<cfset application.test = CreateObject("component", "test")>
<cfoutput>#application.test.foo()#</cfoutput>

This works:

<cfset application.test = CreateObject("component", "test")>
<cfoutput>#application.test.callFoo()#</cfoutput>

This even works:

<cfset application.test = CreateObject("component", "test")>
<cfset request.test = StructCopy(application.test)>
<cfoutput>#request.test.foo()#</cfoutput>

But this fails:

<cfset application.test = CreateObject("component", "test")>
<cfset request.test = StructCopy(application.test)>
<cfoutput>#request.test.callFoo()#</cfoutput>

You get the following error message:

Variable foo is undefined.

Also, if you use this scope inside the cfc, it will fail:

<cfcomponent name="test">
  <cffunction name="foo">
    <cfreturn "blah"/>
  </cffunction>
  <cffunction name="callFoo">
    <cfset temp = this.foo()>
    <cfreturn temp />
  </cffunction>
</cfcomponent>

It works until you try to copy the CFC, after which you get this error:

Variable THIS is undefined.

Can anyone shed any light on why everything within the copy works except for local functions or the scope "this"?

Category tags: Dreamweaver, ColdFusion

Before posting comments or trackbacks, please read the posting policy.

Full Blog Calendar

Pay me securely with your Visa, MasterCard, Discover, or American Express card through PayPal!
Pay me securely with your Visa, MasterCard, Discover, or American Express card through PayPal!
About | Privacy Policy | Contact | License Agreement | ©2002-2020 Tom Muck | Dreamweaver Extensions