Announcement

Collapse
No announcement yet.

Variable scoping

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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?
    Bill Weiland - Emporium Plus http://www.emporiumplus.com/store.mvc
    Online Documentation http://www.emporiumplus.com/tk3/v3/doc.htm
    Question http://www.emporiumplus.com/mivamodu...vc?Screen=SPTS
    Facebook http://www.facebook.com/EmporiumPlus
    Twitter http://twitter.com/emporiumplus

    #2
    Re: Variable scoping

    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!
    Richard Grevers
    Dramatic Design
    New Plymouth, New Zealand

    Comment


      #3
      Re: Variable scoping

      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.
      Last edited by wcw; 08-02-08, 07:10 PM.
      Bill Weiland - Emporium Plus http://www.emporiumplus.com/store.mvc
      Online Documentation http://www.emporiumplus.com/tk3/v3/doc.htm
      Question http://www.emporiumplus.com/mivamodu...vc?Screen=SPTS
      Facebook http://www.facebook.com/EmporiumPlus
      Twitter http://twitter.com/emporiumplus

      Comment


        #4
        Re: Variable scoping

        BTW, I've asked Mark to chime in on this.
        Thanks,

        Rick Wilson
        CEO
        Miva, Inc.
        [email protected]
        https://www.miva.com

        Comment


          #5
          Re: Variable scoping

          I noticed that some variables have global scope that are created without an array variable: ie g.ShipFirstName.

          For example, on the OCST page, the g.baskets variables are in the :baskets array but the customer info are not in an array just global scope. How are the customer info variables created?

          I have found the Basket_Load_ID function but how do I get it to return the d.ship_ and d.bill_ variables in global scope without an array variable?
          http://www.alphabetsigns.com/

          Comment

          Working...
          X