Skip navigation
Currently Being Moderated

Feature for CF11, global LOCAL var scoping

Oct 17, 2013 7:52 PM

I've loved setting scopes in the following manner:

 

<cfset structAppend( VARIABLES, {

     'variableName'         = 'value',

     'variableName2'       = 'anotherValue',

     'variable'                  = 'yetAnotherValue'

}, true ) />

 

It allows me to set variables in 1 command using structure notation, and keeping the command in an easy to digest look.  But a problem I've run into is that I cannot do this with the LOCAL scope and also maintain the best practice of using the 'var' keyword to ensure the variables exist only for the duration of the function call.  For example, this currently fails:

 

<cfset structAppend( var LOCAL, {

     'variable1'     = 'value1',

     'variable2'     = 'value2'

}, true ) />

 

I was hoping the above would equate to the same thing as doing:

 

<cfset var LOCAL.variable1 = 'value1' />

<cfset var LOCAL.variable2 = 'value2' />

 

So I'd love to see CF11 support this.  I know it's menial, but I like using structAppend because it does not remove values that already exist in the scope, but if ones that already exist are provided as well, they are tastefull overwritten.

 
Replies
  • Currently Being Moderated
    Oct 18, 2013 1:03 AM   in reply to Aegis Kleais

    You could also do it like this:

    <cfset var LOCAL = {}>

    <cfset structAppend(LOCAL, {

         'variable1'     = 'value1',

         'variable2'     = 'value2'

    }, true ) />

     

    I'm not sure why you'd want to say "structAppend(var LOCAL".  Also just to complicate things the local scope in your functions you shouldn't need to create as a locally-var'd variable at all; it's in-built since 9.  So really you could just do:

     

    <cfset structAppend(LOCAL, {

         'variable1'     = 'value1',

         'variable2'     = 'value2'

    }, true ) />

     

    job done!  See http://forta.com/blog/index.cfm/2009/6/21/The-New-ColdFusion-LOCAL-Sco pe

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)