Good morning cfml'ers I'm doing some maintenance o...
# lucee
d
Good morning cfml'ers I'm doing some maintenance on an old site, adding a small fw1 app for a new feature. site is running on luce 5.3.10 + fw1 4.3, and i'm hitting something odd, which i'm hoping is just me just not remember variable scoping in cfml correctly. so the following code is in a fw1 view,
Copy code
<cfscript>
if(structKeyExists(rc, "myvalue")) {
    dump(rc.myvalue);
    function test() {
        return rc;
    }
    try {
        test();
    }
    catch(any e) {
        dump(e);
    }
}
</cfscript>
which correctly dumps rc.myvalue, and then catches this error
Copy code
The key [rc] does not exist.
lucee.runtime.exp.ExpressionException: The key [rc] does not exist.
	at lucee.runtime.type.scope.UndefinedImpl.get(UndefinedImpl.java:240)
	at lucee.runtime.type.scope.UndefinedImpl.get(UndefinedImpl.java:184)
	at views.main.test_cfm$cf$c7h.udfCall(/views/main/test.cfm:4)
maybe i'm not remembering this correctly, but i thought functions had access to the calling context variables
d
i had a look at the fw/1 src, and i believe this has to do with the way rc is declared and the view is inlcuded https://github.com/framework-one/fw1/blob/develop/framework/one.cfc#L1981-L1997 it boils down to this example https://trycf.com/gist/fca3c727ee035cf9c0789ae9839f4942/lucee5?theme=monokai
i found a workaround by making the function in the view a closure