Announcement

Collapse
No announcement yet.

Bug or I'm just tired???

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

    Bug or I'm just tired???

    Hello ppl,

    I'll paste you a small code. So, is it me or the result is just odd !!!

    This is the code:
    PHP Code:
    <mvassign name="l.event" value="{'I\'m  a string!'}">
    <
    mveval expr="{'<pre>First occurrence: '$l.event$'</pre>'}">
    <
    mvif expr="{len(l.event:obj) GT 0}">
        <
    mvassign name="l.obj" value="{l.event:obj}">
    <
    mvelseif expr="{len(l.event) GT 0}">
        <
    mvassign name="l.obj" value="{'function(){'$l.event$'}'}">
    <
    mvelse>
        <
    mvassign name="l.obj" value="">
    </
    mvif>
    <
    mveval expr="{'<pre>Second occurrence: '$l.event$'</pre>'}"
    The normal result should be:

    HTML Code:
    First occurrence: I'm  a string!
    Second occurrence: I'm  a string! 
    But instead I have:

    HTML Code:
    First occurrence: I'm  a string!
    Second occurrence:
    So, in this example, the length check of a non existing structure will erase the content if it's a string. Normally len should not impact the variable ... and .. here obviously it does. The workaround is (for me) to back-up the variable before the len check... but it's not very elegant :-)

    So, was I coding too much and I cannot see anymore something obvious... or it's just a bug?

    Thanks,
    Claudiu
    Last edited by Emma; 08-26-11, 03:42 AM.
    Zen Radio : Relax :) : www.zenradio.fm
    MivaScript Tutorials & Scripts : www.mivascript.org

    #2
    Re: Bug or I'm just tired???

    Hi Claudiu,

    If I remember well, this behaviour is documented, or at least rather well known. The first time you access a structure that is not yet defined (usually even in read-only operations), the variable is declared/created, suppressing so the non-structure variable of the name of the base. Not very nice, but am not sure whether it can be called a bug, or rather a feature. You simply need to be very careful when using structured and non-structured variables of the same name. The best practice is avoiding it alltogether. Instead use for example two different members: l.event:value and l.event:obj

    Bet regards,
    Ivo
    Last edited by truXoft; 08-26-11, 04:02 AM.
    Ivo Truxa . @ . t r u X o f t

    Comment


      #3
      Re: Bug or I'm just tired???

      Oh, thank you Ivo. As a matter of fact I wasn't aware about this feature. Thanks for the tip. By the way, nice to see you around here. Log time no see :-)

      Cheers,
      Claudiu
      Zen Radio : Relax :) : www.zenradio.fm
      MivaScript Tutorials & Scripts : www.mivascript.org

      Comment


        #4
        Re: Bug or I'm just tired???

        Ivo Sighting!!!!
        Bruce Golub
        Phosphor Media - "Your Success is our Business"

        Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
        phosphormedia.com

        Comment

        Working...
        X