Title:
Bug 74842:The new handling of local scope breaks included files relying on local variables
| View in TrackerStatus/Resolution/Reason: Closed/Fixed/
Reporter/Name(from Bugbase): Sean Corfield / Sean Corfield (Sean Corfield)
Created: 01/07/2009
Components: Language, CFSCRIPT
Versions: 9.0
Failure Type: Unspecified
Found In Build/Fixed In Build: 0000 / 220702
Priority/Frequency: Major / All users will encounter
Locale/System: English / Platforms All
Vote Count: 1
Problem:
The new handling of local scope breaks included files relying on local variables.
A common approach in framework-style code is to include a view page inside a UDF/method. The view should be able to see any local variables defined in the including function.
CF9's handling of local scope has completely changed from CF8 in this area.
Method:
Create the following two CFML pages in a directory and run the second one on both CF8 and CF9 to see the difference in output.
<!--- inc.cfm --->
<cfset localIsDefined = isDefined("local") />
<cfset testIsDefined = isDefined("test") />
<cfset localDotTestIsDefined = false />
<cfif localIsDefined>
<cfset localDotTestIsDefined = structKeyExists(local,"test") />
<cfset theLocalScope = local />
</cfif>
<!--- test.cfm --->
<cffunction name="tryInclude1">
<cfset var local = {} />
<cfset local.test = true />
<cfinclude template="inc.cfm" />
</cffunction>
<cffunction name="tryInclude2">
<cfset var test = true />
<cfinclude template="inc.cfm" />
</cffunction>
<cffunction name="tryInclude3">
<cfset local.test = true />
<cfinclude template="inc.cfm" />
</cffunction>
<cfset tryInclude1() />
<cfdump var="#variables#"/>
<cfset tryInclude2() />
<cfdump var="#variables#"/>
<cfset tryInclude3() />
<cfdump var="#variables#"/>
Result:
No error message - behavior is very different between CF8 and CF9.
----------------------------- Additional Watson Details -----------------------------
Watson Bug ID: 3037197
External Customer Info:
External Company:
External Customer Name: Sean Corfield
External Customer Email: 479B4EDC43F3A88B992016B6
External Test Config: 01/07/2009
Attachments:
Comments: