I am trying to update a legacy where we have some ...
# cfml-general
g
I am trying to update a legacy where we have some undefined variables without scopes, now with latest update, it seems it started creating problems, i have created a function but i wonder if there is a abtter way because it will run every time on te page to check and detect and see ifthe ey has been defined in a scope or not more worry is about the session,form,url
Copy code
<cffunction name="getOrSetScopeValue" returntype="any" output="false">
    <cfargument name="key" type="string" required="true">
    <cfargument name="defaultValue" type="any" required="false" default="">

    <cfset var scopes = ["variables", "arguments", "local", "form", "url", "application", "session", "request"]>
    <cfset var value = "">

    <cfloop array="#scopes#" index="scope">
        <cfif structKeyExists(evaluate(scope), arguments.key)>
            <cfset value = evaluate(scope & "." & arguments.key)>
            <cfbreak>
        </cfif>
    </cfloop>

    <cfif value EQ "">
        <cfset value = arguments.defaultValue>
        <cfset variables[arguments.key] = value>
    </cfif>

    <cfreturn value>
</cffunction>
m
I think you would be better off temporarily having the JVM flag that adobe provided to allow the default behavior to work for now.. And then utilize the patch that adobe provided to log the use of un-scoped variables so you can fix them.
👆 1
👆🏻 1
g
which patch you are talking about - And then utilize the patch that adobe provided to log the use of un-scoped variables so you can fix them
m
g
what if someone is still using Application.cfm, i know its sounds off bu cannot edit jvm if have to what is the right way
m
I believe that there is a tool that was created to help scan for these as well... https://fixinator.app/ ,,, now it isn't free.. but neither is your time having to be reactionary...
☝🏼 1
g
Also: you can use a linter. @Gareth has made a recent for and added in some recent fixes to the KamasamaK editor https://marketplace.visualstudio.com/items?itemName=CFMLEditor.cfmleditor And there is a "matching" linter, too. https://marketplace.visualstudio.com/items?itemName=CFMLEditor.cfmleditor-lint You can have it search your entire project or individual files as you open them / edit them / save them - it is pretty configurable.