Skip to main content
5TagWalt
Participating Frequently
May 3, 2010
Question

Is CF9 local scope meant only for functions?

  • May 3, 2010
  • 1 reply
  • 1952 views

Our codebase is pretty extensive in creating structs named local , then appending form and url scopes to that newly created struct. (the why's are another discussion)

What we've found is that the new, explicit local scope breaks our code.
Now, moving things into the request scope fixes the issue fine, however, it will wind up being rather tedious, as at times we don't get any exceptions.

The code just assumes a condition is false and continues down another path.

We've also found rather bizarre behavior by the local scope.

On one particular template, we can dump the local scope, and see variables that we test for with isDefined. When testing with a dynamic loop counter as part of the variable name, it fails.

If we hard code a number (as an example, isDefined('Filter_1')   versus isDefined('Filter_#loopCount#') ) , the test will work fine. With the variable in the test, it fails.

Is the end result that we just have to change our code? Or is this aberrant behavior?

Thanks.

    This topic has been closed for replies.

    1 reply

    Inspiring
    May 3, 2010

    Do you see the same behavior if you use StructKeyExists() instead of IsDefined()?

    5TagWalt
    5TagWaltAuthor
    Participating Frequently
    May 3, 2010

    StructKeyExists works fine, yes.

    And yes, I realize that the final answer more or less will be to use that or to move things into the request scope. My question, I suppose, is academic.

    The documentation doesn't explicitly say (or I missed where it did) that the local scope was intended for CFC/function level use only.

    Inspiring
    May 5, 2010

    Can you provide a stand-alone test case that demonstrates the issuse?

    --

    Adam