Friday, 28 November 2014

Local scope bug (or not, if you're the ColdFusion Team)

I just spotted this, and decided to look into it:

This defines a bugsituationbug in ColdFusion wherein if one deletes a local-scoped variable from a function, then assign an unscoped variable, that new variable goes back in the local scope, not in the variables scope.

Here's the repro, courtesy of Aaron Neff:

// localScopeBug.cfm
function myFunction() {
    var myVar="";
    structDelete(local, "myVar", true);
    myVar="value for myVar";

On ColdFusion (11, but obviously earlier too), I get this:

The following information is meant for the website developer for debugging purposes.
Error Occurred While Processing Request

Element MYVAR is undefined in VARIABLES.

The error occurred in C:/wwwroot/blogExamples/coldfusion/bugs/localScopeBug.cfm: line 9
7 :  structClear(local);
8 :  myVar="value for myVar";
9 :  writeOutput(variables.myVar);
10 : }
11 : myFunction();

On Railo, on the other hand, I get the more expected:

value for myVar

I'd not be raising this fairly edge-case-y situation other than for Adobe's reaction to it. It's just been closed as:

State Closed
Status Withdrawn
Reason NotABug
For once had you closed it as "can't be arsed", I'd probably agree with you. However it is a bug.

Or is it?

What do you think?

BTW: I know I am falling behind on two things: feeding back on the survey about PHP date handling, and also following up the quiz from a few weeks back. This week has been crazy at work, and I just can't be arsed looking at a computer when I get home. Once again there's rugby to watch this weekend, but I might have a chance to look at some code on Saturday morning, and perhaps Sunday. All of this is still on my radar.