Hi, i’ve been a long time CFML developer and I have to admit, i’ve never set a variable as <cfset variables.thing = 1>. I always use <cfset thing = 1> syntax.
Since isDefined() is deemed insecure, so if a variable is not a struct, how do we detect it with structKeyExists() ?
Everywhere I read it says to use the “variables” scope. so structKeyExists(variables, “thing”) should detect it. But it doesn’t.
“The VARIABLES scope is the default scope in ColdFusion. i.e. if a variable is declared in .cfm and .cfc file without explicitly prefixing a scope, or without ‘var’ to a variable inside a function, ColdFusion assigns VARIABLES scope to that variable.”
But then, when testing it out (and also my experience in my own codebase) I get the following situation:
Can someone explain to me where I am going wrong? And how can I use anything other than isDefined() to detect if a variable is defined when scope is not specified?
Perhaps its a setting in Lucee admin i’m not aware of?
Or, is it possible that the docs are wrong? They are most certainly misleading!!!
Thanks at least I know i’m not losing my mind here.
I am hoping somebody who is a Lucee Contributer maybe can chime in to bring in some understanding. The Docs are so explicit with how it should work. Its shocking to have it just straight up fail to do what it says it is going to do.
Somebody help!!! I actually have a coding situation that is breaking as a result of this. Its becoming really annoying to have to refactor a bunch of stuff because Lucee is not working as expected with regards to this.
I’ve read once somewhere that Trycf might do some unknown/hidden scoping stuff. I think @AdamCameron wrote something about it in slack somewhere after experimenting, but I can’t say for sure. May be he knows more about it.
I’m on Lucee 5.3.12 on Windows. So according to the table BK_BK posted, i should not expect it to work in any version of Lucee 5 but I can expect it to work in Lucee 6?
5.3.12 on Windows. I wonder if there is a difference between linux and windows versions with respect to this. According the replies to my post i’m seeing, there is.
No with all due respect, the reason I made this post was because my production and development evnironments running Lucee 5.3.12 on Windows were having this issue. And then I tried on TryCF and I got the same result. So I wrote the post to try and figure out. Is it a setting? Some other environmental factor ?
However, if I dump(variables) on that version I get a NULL Pointer Exception with my Java 11.0.23, so there might be some issues regarding the variables scope on 5.3.2.77.
<cfscript>
test = 1;
dump([server.lucee.version,StructKeyExists( variables, "test" )] ); //true
dump(variables);// throws null pointer exception on 5.3.2.77
</cfscript>
But on actual Lucee 6.1.0.243 it works fine:
What works on scopes and what not on trycf.com is another story and I’d ignore that and make decisions on my own versions. As already told, trycf does some scoping changes on the code you submit.
If that scoping issue would be in such a way you’ve described, we would have a lots of requests here in the forum. And I don’t know about any config settings dealing with changing that scope.
Also, I’d recommend not using 5.3.2.77 at all anymore because of the known CVEs. I’d focus on moving to the 5.4 LTS version or maybe even 6.x.