Accessibility

TechNote

ColdFusion 9 - local scope

Issue


Since “local” is a scope in ColdFusion 9, using code similar to the following can result in a change of behavior:

<cfcomponent output="false" extends="centaur.base">

<cfset variables.cfc = structNew() />

<cfset cfc.dsn.dsn1 = "dsn1" />

<cffunction name="test" access="public" output="true" returntype="void">

<cfset var local = structNew() />

<cfdump var="#cfc#">

<cfset local.cfc = structNew() />

<cfdump var="#cfc#">

</cffunction>

</cfcomponent>

In this case, first instance of dump shows variables.cfc and second instance shows local.cfc. This is change in behavior as in previous ColdFusion releases, second instance of dump would have picked variables.cfc.

Reason


Inside a function if a variable is defined in both variable scope and local scope, and is accessed without any scope prefix, it will be retrieved from local scope. This can cause change in behaviour from ColdFusion 8 if "local" was used.

Solution


To retain backward compatibility, refer 'cfc' with explicit scope, that is variables.cfc 

Additional Information


 

 

AlertThis content requires Flash

To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.

Download the free Flash Player now!

Get Adobe Flash Player

Creative Commons License

Search Support


Document Details

ID:cpsid_51710

Products Affected:

coldfusion