tracker issue : CF-3037197

select a category, or use search below
(searches all categories and all time range)
Title:

Bug 74842:The new handling of local scope breaks included files relying on local variables

| View in Tracker

Status/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:

+1 - I also see this is a change in behavior, and is an issue. forum thread: https://prerelease.adobe.com/project/forum/thread.html?cap=87529bda13744b3db718e841890b9240&forid={a8760b70-42a5-45fc-8ba2-dfcf173a9580}&topid={6804d73f-4f55-4884-b6b8-0c3896d60a06}&tp=2&prr=0&a=added_r#
Vote by External U.
24233 | November 10, 2011 07:11:29 PM GMT