Title:
Var scope continues to be in effect even after local-scoped variable becomes null
| View in TrackerStatus/Resolution/Reason: Closed/Withdrawn/AsDesigned
Reporter/Name(from Bugbase): A. B. / ()
Created: 03/10/2019
Versions: 2018
Failure Type: Others
Found In Build/Fixed In Build: 2018.0.02.314033 /
Priority/Frequency: Normal /
Locale/System: / Platforms All
Vote Count: 0
Problem Description:
In a function the function-local (var) scope continues to be in effect in memory after an originally var-scoped variable becomes null.
Steps to Reproduce:
Create and run a CFM page containing the following code
<cfscript>
f();
void function f () {
// Assign testVar
var testVar=1;
var isTestVarNull=isNull(local.testVar);
var isTestVarDefinedInLocalScope=isDefined("local.testVar");
var isTestVarKeyInLocalStruct=structKeyExists(local, "testVar");
writedump(var=local,label="Local scope: first dump - with assignment 'var testVar=1;'");
// TestVar now takes null value
testVar=cacheget("nonExistentCacheId");
isTestVarNull=isNull(local.testVar);
isTestVarDefinedInLocalScope=isDefined("local.testVar");
isTestVarKeyInLocalStruct=structKeyExists(local, "testVar");
writedump(var=local,label="Local scope: second dump - after testVar takes null value");
// Reassign testVar
testVar=5;
isTestVarNull=isNull(local.testVar);
isTestVarDefinedInLocalScope=isDefined("local.testVar");
isTestVarKeyInLocalStruct=structKeyExists(local, "testVar");
writedump(var=local,label="Local scope: third dump - after reassignment 'testVar=5;' (without 'var')");
}
</cfscript>
This code assigns the function-local variable testVar the value 1. After that, testVar is made to become null. Then follows the assignment testVar=5, without scope.
Actual Result (see attached dumps):
isTestVarNull is No;
isTestVarDefinedInLocalScope is Yes;
isTestVarKeyInLocalStruct is Yes;
Expected Result:
I expected testVar, and any references to it, to have disappeared from memory. I also expected that, following the null assignment, the assignment testVar=5 (without scope) would define a new variable in variables scope. Hence that:
isTestVarNull is Yes;
isTestVarDefinedInLocalScope is No;
isTestVarKeyInLocalStruct is No;
Any Workarounds:
Not relevant
Attachments:
Comments: