Weird result?? php 4.4.0

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bob Stearns

    Weird result?? php 4.4.0

    I have a variable v with the value -1. After v++ it has the value "" not
    0. Since I am using it for a subscript, the "" value is not overwriting
    the 0 element of the array as desired. Should v++ ever give a
    non-numeric value?
  • Andy Hassall

    #2
    Re: Weird result?? php 4.4.0

    On Thu, 27 Jul 2006 17:47:50 -0400, Bob Stearns <rstearns1241@c harter.net>
    wrote:
    >I have a variable v with the value -1. After v++ it has the value "" not
    >0. Since I am using it for a subscript, the "" value is not overwriting
    >the 0 element of the array as desired. Should v++ ever give a
    >non-numeric value?
    No - post a script and output demonstrating this?

    Since you're not on the latest release of a branch the standard advice would
    be "upgrade", though, if this actually happens.

    --
    Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
    http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

    Comment

    • PTM

      #3
      Re: Weird result?? php 4.4.0

      "Bob Stearns" <rstearns1241@c harter.netwrote in message
      news:bwayg.1867 $2M3.354@fe04.l ga...
      >I have a variable v with the value -1. After v++ it has the value "" not 0.
      >Since I am using it for a subscript, the "" value is not overwriting the 0
      >element of the array as desired. Should v++ ever give a non-numeric value?
      I used to use a variable initialised with -1, and never noticed the problem
      you are having.
      What are you trying to do with it and have you got an example of the code so
      we can see what's going on?

      Phil


      Comment

      • Bob Stearns

        #4
        Re: Weird result?? php 4.4.0

        Andy Hassall wrote:
        On Thu, 27 Jul 2006 17:47:50 -0400, Bob Stearns <rstearns1241@c harter.net>
        wrote:
        >
        >
        >>I have a variable v with the value -1. After v++ it has the value "" not
        >>0. Since I am using it for a subscript, the "" value is not overwriting
        >>the 0 element of the array as desired. Should v++ ever give a
        >>non-numeric value?
        >
        >
        No - post a script and output demonstrating this?
        >
        Since you're not on the latest release of a branch the standard advice would
        be "upgrade", though, if this actually happens.
        >
        Here is a script fragment and the debugging output therefrom:

        dosql($sql, "S AUI 3", -1, "", $res, $n);
        $debug .= "<br>stk_ptr=$s tk_ptr; ";
        while($x=odbc_f etch_array($res )) {
        $debug .= "<br>x="; debug_var($x); $debug .= "<br>";
        $item_list[$n_animals] = $x["ITEM_ID"];
        $free = $x["FREE_PART"];
        $free_list[$n_animals] = $free;
        if($free!="Y") $chg_animals++;
        $n_animals++;
        $stk_ptr++;
        $stack[$stack_ptr] = array($x["LOT_NUMB"], $x["LOT_SUFFIX "]);
        $debug .= "<br>stk_ptr=$s tkptr; stack=";
        debug_var($stac k);
        $debug .= "<br>";

        stk_ptr=-1;
        x=array 14 { ITEM_ID=>29; AUCTION_ID=>21; BHID=>77143; LOT_NUMB=>11;
        LOT_SUFFIX=>; SALE_ORDER=>; FOOTNOTES=>; CATALOG_UPDATE= >; COMMENTX=>;
        PRINT_CATALOG=> Y; PART_OF_LOT_NUM B=>13; PART_OF_LOT_SUF FIX=>;
        FREE_PART=>Y; CATEGORY=>; }


        stk_ptr=; stack=array 2 { 0=>array 2 { 0=>13; 1=>; }
        =>array 2 { 0=>11; 1=>; }
        }

        As you can see, stk_ptr is "", and so when it is used as a subscript,
        stack[0] is not overwritten, which hangs the whole script in an infinite
        loop.

        Comment

        • Bob Stearns

          #5
          Re: Weird result?? php 4.4.0

          PTM wrote:
          "Bob Stearns" <rstearns1241@c harter.netwrote in message
          news:bwayg.1867 $2M3.354@fe04.l ga...
          >
          >>I have a variable v with the value -1. After v++ it has the value "" not 0.
          >>Since I am using it for a subscript, the "" value is not overwriting the 0
          >>element of the array as desired. Should v++ ever give a non-numeric value?
          >
          >
          I used to use a variable initialised with -1, and never noticed the problem
          you are having.
          What are you trying to do with it and have you got an example of the code so
          we can see what's going on?
          >
          Phil
          >
          >
          Here is a script fragment and the debugging output therefrom:

          dosql($sql, "S AUI 3", -1, "", $res, $n);
          $debug .= "<br>stk_ptr=$s tk_ptr; ";
          while($x=odbc_f etch_array($res )) {
          $debug .= "<br>x="; debug_var($x); $debug .= "<br>";
          $item_list[$n_animals] = $x["ITEM_ID"];
          $free = $x["FREE_PART"];
          $free_list[$n_animals] = $free;
          if($free!="Y") $chg_animals++;
          $n_animals++;
          $stk_ptr++;
          $stack[$stack_ptr] = array($x["LOT_NUMB"], $x["LOT_SUFFIX "]);
          $debug .= "<br>stk_ptr=$s tkptr; stack=";
          debug_var($stac k);
          $debug .= "<br>";

          stk_ptr=-1;
          x=array 14 { ITEM_ID=>29; AUCTION_ID=>21; BHID=>77143; LOT_NUMB=>11;
          LOT_SUFFIX=>; SALE_ORDER=>; FOOTNOTES=>; CATALOG_UPDATE= >; COMMENTX=>;
          PRINT_CATALOG=> Y; PART_OF_LOT_NUM B=>13; PART_OF_LOT_SUF FIX=>;
          FREE_PART=>Y; CATEGORY=>; }


          stk_ptr=; stack=array 2 { 0=>array 2 { 0=>13; 1=>; }
          =>array 2 { 0=>11; 1=>; }
          }

          As you can see, stk_ptr is "", and so when it is used as a subscript,
          stack[0] is not overwritten, which hangs the whole script in an infinite
          loop.

          Comment

          • Andy Hassall

            #6
            Re: Weird result?? php 4.4.0

            On Thu, 27 Jul 2006 18:14:02 -0400, Bob Stearns <rstearns1241@c harter.net>
            wrote:
            >Andy Hassall wrote:
            >On Thu, 27 Jul 2006 17:47:50 -0400, Bob Stearns <rstearns1241@c harter.net>
            >wrote:
            >>>I have a variable v with the value -1. After v++ it has the value "" not
            >>>0. Since I am using it for a subscript, the "" value is not overwriting
            >>>the 0 element of the array as desired. Should v++ ever give a
            >>>non-numeric value?
            >>
            > No - post a script and output demonstrating this?
            >>
            > Since you're not on the latest release of a branch the standard advice would
            >be "upgrade", though, if this actually happens.
            >>
            >Here is a script fragment and the debugging output therefrom:
            [snip]
            >
            >stk_ptr=; stack=array 2 { 0=>array 2 { 0=>13; 1=>; }
            >=>array 2 { 0=>11; 1=>; }
            >}
            >
            >As you can see, stk_ptr is "", and so when it is used as a subscript,
            >stack[0] is not overwritten, which hangs the whole script in an infinite
            >loop.
            Can you reduce this to a script that can be run stand-alone?

            --
            Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
            http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

            Comment

            • Alvaro G. Vicario

              #7
              Re: Weird result?? php 4.4.0

              *** Bob Stearns escribió/wrote (Thu, 27 Jul 2006 17:47:50 -0400):
              I have a variable v with the value -1. After v++ it has the value "" not
              0. Since I am using it for a subscript, the "" value is not overwriting
              the 0 element of the array as desired. Should v++ ever give a
              non-numeric value?
              Can you post actual PHP code we can copy, paste and try?

              Never mind, I suppose you're casting numbers from/to strings. Check the
              "Type Juggling" chapter in PHP manual.


              --
              -+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
              ++ Mi sitio sobre programación web: http://bits.demogracia.com
              +- Mi web de humor con rayos UVA: http://www.demogracia.com
              --

              Comment

              • Bob Stearns

                #8
                Re: Weird result?? php 4.4.0

                Alvaro G. Vicario wrote:
                *** Bob Stearns escribió/wrote (Thu, 27 Jul 2006 17:47:50 -0400):
                >
                >>I have a variable v with the value -1. After v++ it has the value "" not
                >>0. Since I am using it for a subscript, the "" value is not overwriting
                >>the 0 element of the array as desired. Should v++ ever give a
                >>non-numeric value?
                >
                >
                Can you post actual PHP code we can copy, paste and try?
                >
                Never mind, I suppose you're casting numbers from/to strings. Check the
                "Type Juggling" chapter in PHP manual.
                >
                >
                My error. Twice I mistyped the variable $stk_ptr; once as $stkptr and
                once as $stack_ptr. The errors offset each other in such a way as to
                lead me to the erroneous conclusion about ++.

                Comment

                • Bob Stearns

                  #9
                  Re: Weird result?? php 4.4.0

                  Andy Hassle wrote:
                  On Thu, 27 Jul 2006 18:14:02 -0400, Bob Stearns <rstearns1241@c harter.net>
                  wrote:
                  >
                  >
                  >>Andy Hassall wrote:
                  >>
                  >>>On Thu, 27 Jul 2006 17:47:50 -0400, Bob Stearns <rstearns1241@c harter.net>
                  >>>wrote:
                  >>>
                  >>>>I have a variable v with the value -1. After v++ it has the value "" not
                  >>>>0. Since I am using it for a subscript, the "" value is not overwriting
                  >>>>the 0 element of the array as desired. Should v++ ever give a
                  >>>>non-numeric value?
                  >>>
                  >>No - post a script and output demonstrating this?
                  >>>
                  >>Since you're not on the latest release of a branch the standard advice would
                  >>>be "upgrade", though, if this actually happens.
                  >>>
                  >>
                  >>Here is a script fragment and the debugging output therefrom:
                  >
                  [snip]
                  >
                  >>stk_ptr=; stack=array 2 { 0=>array 2 { 0=>13; 1=>; }
                  >>=>array 2 { 0=>11; 1=>; }
                  >>}
                  >>
                  >>As you can see, stk_ptr is "", and so when it is used as a subscript,
                  >>stack[0] is not overwritten, which hangs the whole script in an infinite
                  >>loop.
                  >
                  >
                  Can you reduce this to a script that can be run stand-alone?
                  >
                  My error. Twice I mistyped the variable $stk_ptr; once as $stkptr and
                  once as $stack_ptr. The errors offset each other in such a way as to
                  lead me to the erroneous conclusion about ++.

                  Comment

                  • Henk Verhoeven

                    #10
                    Re: Weird result?? php 4.4.0

                    Bob Stearns wrote:
                    (..)
                    My error. Twice I mistyped the variable $stk_ptr; once as $stkptr and
                    once as $stack_ptr. The errors offset each other in such a way as to
                    lead me to the erroneous conclusion about ++.
                    Hi Bob,

                    If you set error reporting to E_ALL php will tell you about these
                    typo's. Once you got your code cleaned up it can save you a lot of time ;-)

                    call from the top of your script:
                    error_reporting (E_ALL);

                    or in php.ini change the line:
                    error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT

                    into:
                    error_reporting = E_ALL & ~E_STRICT

                    (for php4 leave out & ~E_STRICT)

                    Greetings,

                    Henk Verhoeven,
                    www.phpPeanuts.org.

                    Comment

                    Working...