CF8 vs CF10: the local region declared by the parent is not visible in child functions

I have quite a bit of code written for ColdFusion 8 that fails in ColdFusion 10. I understand that CF9 and later versions treat the Local area differently from the previous one. My problem is that I encoded functions to extend each, in the sense that child instances inherit variables from the parent. But just to clearly indicate what I mean, let me give an example of what works and how it does not work in CF10.

Take two CFCs, a child CFC that extends the parent CFC:

<!--- Parent.cfc --->
<cfcomponent displayname="Parent">

    <cffunction name="SomeFunction" output="yes">
        <cfset local.parent_val = "Declared in parent instance">
    </cffunction>

</cfcomponent>



<!--- Child.cfc --->
<cfcomponent displayname="Child" extends="Parent">
    <cffunction name="SomeFunction" output="yes">
    <cfset local.child_val = "Declared in child instance">

    <!--- The following "super" call will instantiate the "parent_val" variable
    from within the parent CFC version of this function... but only in CF8? --->
    <cfset Super.SomeFunction() />

    <p>#local.child_val#</p>
    <p>#local.parent_val#</p>
    </cffunction>
</cfcomponent>

Called as:

<cfset ChildCFC = CreateObject("component","Child") />
<cfoutput>#ChildCFC.SomeFunction()#</cfoutput>

In CF8, I get: Declared in child instance Declared in parent instance

In CF10, I get: Declared in child instance [error dump showing "Element PARENT_VAL is undefined in LOCAL."]

, CF10 ( "" ) , , , CF8.

, : , ? , , ?

, "" , , SUPER ( ). , CF8 , .

+4
2

CF8 SomeFunction() Parent.cfc

local.parent_val = blah // sets to variables.local.parent_val, dies with object

CF9 SomeFunction() Parent.cfc

local.parent_val = blah // eqv to var parent_val, dies right after function quits

CF8 . , var local = {} . CF9 +.

, , local. variables. , .

+5

, Local CF8 Variables, , - . CF8 LOCAL var

<cfset var Local={}>

var. , (, ), . , , Variables

<cfset local.parent_val = "Declared in parent instance">

to

<cfset Variables.parent_val = "Declared in parent instance">

. CF8 - , , CF10 ( ). , , VAR. , , .

0

All Articles