Title: Persistence of unnamed-scope

Greetings, all.

As my organization has yet to install the 6.1 update, I am unable to take advantage of the variables-scope-like-use inside any CFCs. Once I can, my problem may be resolved; unfortunately, I can't wait that long to know.

The issue: I've got several components, each outlining their properties with the cfproperty tag, and each possessing an init() method wherein I pass a datasource collection and create the internal variables with any defaults.

Example:
<cfcomponent output="no">
  <cfproperty name="aProperty" type="string" default="" />
  <cffunction name="init" output="no" returntype="boolean">
    <cfif ArrayLen(arguments) GT 0>
      <cfif IsStruct(arguments[1])>
        <cfset DSN = arguments[1] />
      </cfif>
    </cfif>
    <cfset aProperty = "" />
    <cfreturn true />
  </cffunction>
</cfcomponent>

No problem, right? I invoke all of my CFCs with the CreateObject() function, then init() their variables, passing the DSN structure if the component is to access the database. I have yet to have a problem with this.

When I add another method, it doesn't seem to be able to see the value of the properties set by the init() function.
Example:
<cffunction name="getAProperty" returntype="string">
  <cfreturn aProperty />
</cffunction>

This returns to my invoking template the following value:
  [empty string]
Were aProperty to be an array, and the returntype of getAProperty() to be specified as "array" I would receive the error

  "The value returned from function getAProperty() is not of type array."

Is the only way to maintain semi-private variables in the unnamed scope by creating them in the "constructor area" between property and function definitions?

Please help. You've taught me so much and I have so much more to learn.

Thanks,
ecd.

Reply via email to