View Full Version : Variable scoping
In the past if you used a variable in mivascript and did not scope it, empresa would first look for the global with that name, then continue through database scope and finally local scope. Scoping is good thing as the engine does not have to go through a heirarchy to find the variable. Occasionally, I miss that scope. Everything works fine on the server my test store is on when the scope is omitted. However, I just came across a case which behaved differently. The variable without the scope came up blank even though their was a global version of that variable.
Is it a bug in the empresa version that allow the non-scoped variable or is it a bug in the empresa that failed to go through the heirarchy?
Dramatic
08-03-08, 04:33 AM
Are you ssure it doesn't look for local first? (local as an "override" for global). Certainly scoping resolves such problems, even in 3.97, where I still do most of my work.
BTW, when the compiler first came out, I did some research on the speed of various operations. One of the most significant findings was that retrieving a scoped variable is four times faster than unscoped. So it pays to scope!
It is global (when no scope is defined) in that it assigns it to be global. The order evaluated is not the issue. If it is not scoped, with one of the empresa's tested, it did not check any scope (g,l,s,d). It just returned no value when the scope was left off. That has not been the behavior in the past. As you said, scoping is faster, but it will still return a result without it. In this case, it did not. The question is what is the bug?
1) scoping is now mandatory
or
2) empresa not checking the heirarchy of scopes
What ever the answer is, it should be on all versions of empresa for all OS.
If scope is not defined, the Virtual Machine checks to see if a previously scoped variable of same name exists and has scope in current location, in the following order:
o system variable (s.var or system.var)
o local variable (l.var or local.var)
o database variable (d.var or database.var)
o global variable (g.var or global.var or var)
o if no variable var (with any prefix) exists, then, var is created as a global variable
In the scenario the variable was already created. I was simply reading it. Without putting a scope on the mvt:if expr=var it found nothing. By putting g.var it found it.
Rick Wilson
08-04-08, 05:18 PM
BTW, I've asked Mark to chime in on this.
vBulletin® v3.7.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.