Class variable problem

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

    Class variable problem

    Hello,

    I have this class http://pastebin.com/807571, where I set some variables on
    __construct. Originaly I set the $total_? variables when the function
    showLayout() was called. I know pastebin is having problems, so if you can't
    get the code, I will upload it in plain text on my own server.
    This function is called from a page object, which is called from a
    controller and so on.
    Doing it this way meant that all variables set during the showLayout()
    function, were set to null, next time I opened the object.
    Then I set it up like it is now, where I set all call variables doring
    __construct and this worked fine.
    But now the problem is, that the last values added to the class variables
    from the showLayout() function are not added.

    Is this a bug in PHP5 or am I doing something terribly wrong here?

    Best regards, tatsudoshi


  • tatsudoshi

    #2
    Re: Class variable problem

    I have uploaded the class at http://www.criion.net/class.Kurv.php.txt


    Comment

    • Colin Fine

      #3
      Re: Class variable problem

      tatsudoshi wrote:
      Hello,
      >
      I have this class http://pastebin.com/807571, where I set some variables on
      __construct. Originaly I set the $total_? variables when the function
      showLayout() was called. I know pastebin is having problems, so if you can't
      get the code, I will upload it in plain text on my own server.
      This function is called from a page object, which is called from a
      controller and so on.
      Doing it this way meant that all variables set during the showLayout()
      function, were set to null, next time I opened the object.
      Then I set it up like it is now, where I set all call variables doring
      __construct and this worked fine.
      But now the problem is, that the last values added to the class variables
      from the showLayout() function are not added.
      >
      Is this a bug in PHP5 or am I doing something terribly wrong here?
      >
      Best regards, tatsudoshi
      >
      >
      You'll need to be more explicit about what you're expecting to see, and
      what you are seeing.

      I thought it might be a problem with references (in PHP5 Objects are
      copied by references, but arrays are not) but I can't see a place where
      you're assigning to a copied array, so it doesn't appear to be that.

      Colin

      Comment

      • Jerry Stuckle

        #4
        Re: Class variable problem

        tatsudoshi wrote:
        Hello,
        >
        I have this class http://pastebin.com/807571, where I set some variables on
        __construct. Originaly I set the $total_? variables when the function
        showLayout() was called. I know pastebin is having problems, so if you can't
        get the code, I will upload it in plain text on my own server.
        This function is called from a page object, which is called from a
        controller and so on.
        Doing it this way meant that all variables set during the showLayout()
        function, were set to null, next time I opened the object.
        Then I set it up like it is now, where I set all call variables doring
        __construct and this worked fine.
        But now the problem is, that the last values added to the class variables
        from the showLayout() function are not added.
        >
        Is this a bug in PHP5 or am I doing something terribly wrong here?
        >
        Best regards, tatsudoshi
        >
        >
        The real question here is - how are you opening the object? Are you
        creating a second object or are you referencing the existing object.

        The code you're using to access it is also very important.

        --
        =============== ===
        Remove the "x" from my email address
        Jerry Stuckle
        JDS Computer Training Corp.
        jstucklex@attgl obal.net
        =============== ===

        Comment

        • tatsudoshi

          #5
          Re: Class variable problem

          This is a snip of the code from my controller. Each page has a pagecode,
          from which I select a case in a switch structur. On Kurv page, it checks to
          see if the object is set, and if, gets the array from the object, otherwise
          it creates the array and handles all the array related things. At the end of
          the case it does this snip shown.

          What it is suppose to do is first check if the useraccount can order the
          item the user is trying to order.
          That it check to see if the object is set, this time to either add the
          array, with the new item or create a Kurv object.

          I save all objects in SESSION.

          if($wrong_user_ account) {
          $output = <<<hds
          <div id='generic-content'>
          <p>Denne type abonnement, kan ikke bestilles med denne konto.</p>
          </div
          hds;
          $obj_kurv_go = new GenericOutput($ output);
          }
          elseif(isset($t his->obj_kurv)) {
          $this->obj_kurv->setArray($arra y);
          if(array_key_ex ists("action", $_GET) && $_GET["action"] !=
          "add_to_bas ket"
          || array_key_exist s("tilbud_id" , $_GET))
          $this->obj_kurv->storeLinkBack( $_SERVER["HTTP_REFER ER"]);

          $obj_kurv_go = $this->obj_kurv;
          }
          else {
          $link_to_basket = $this->readPage(array ("mapr" ="byCode",
          "sql_id" ="p_kurv_liste" ))->getPageId();
          $link_to_bestil = $this->readPage(array ("mapr" ="byCode",
          "sql_id" ="p_bestil_1 "))->getPageId();
          $link_to_teleca re = $this->readPage(array ("mapr" ="byCode",
          "sql_id" ="p_telecare "))->getPageId();

          $this->obj_kurv = new Kurv($array, $link_to_basket );
          $this->obj_kurv->storeLinkBack( $_SERVER["HTTP_REFER ER"]);
          $this->obj_kurv->storeLinkToBes til($link_to_be stil);
          $this->obj_kurv->storeLinkToTel ecare($link_to_ telecare);
          $obj_kurv_go = $this->obj_kurv;
          }
          }
          $contents["gen_out"] = array($obj_kurv _go);


          Comment

          • tatsudoshi

            #6
            Class variable problem

            Hello,

            I have this class http://pastebin.com/807571, where I set some variables on
            __construct. Originaly I set the $total_? variables when the function
            showLayout() was called. I know pastebin is having problems, so if you can't
            get the code, I will upload it in plain text on my own server.
            This function is called from a page object, which is called from a
            controller and so on.
            Doing it this way meant that all variables set during the showLayout()
            function, were set to null, next time I opened the object.
            Then I set it up like it is now, where I set all call variables doring
            __construct and this worked fine.
            But now the problem is, that the last values added to the class variables
            from the showLayout() function are not added.

            Is this a bug in PHP5 or am I doing something terribly wrong here?

            Best regards, tatsudoshi

            Added:
            I have uploaded the class at http://www.criion.net/class.Kurv.php.txt

            Added:
            This is a snip of the code from my controller. Each page has a pagecode,
            from which I select a case in a switch structur. On Kurv page, it checks to
            see if the object is set, and if, gets the array from the object, otherwise
            it creates the array and handles all the array related things. At the end of
            the case it does this snip shown.

            What it is suppose to do is first check if the useraccount can order the
            item the user is trying to order.
            That it check to see if the object is set, this time to either add the
            array, with the new item or create a Kurv object.

            I save all objects in SESSION.

            if($wrong_user_ account) {
            $output = <<<hds
            <div id='generic-content'>
            <p>Denne type abonnement, kan ikke bestilles med denne konto.</p>
            </div
            hds;
            $obj_kurv_go = new GenericOutput($ output);
            }
            elseif(isset($t his->obj_kurv)) {
            $this->obj_kurv->setArray($arra y);
            if(array_key_ex ists("action", $_GET) && $_GET["action"] !=
            "add_to_bas ket"
            || array_key_exist s("tilbud_id" , $_GET))
            $this->obj_kurv->storeLinkBack( $_SERVER["HTTP_REFER ER"]);

            $obj_kurv_go = $this->obj_kurv;
            }
            else {
            $link_to_basket = $this->readPage(array ("mapr" ="byCode",
            "sql_id" ="p_kurv_liste" ))->getPageId();
            $link_to_bestil = $this->readPage(array ("mapr" ="byCode",
            "sql_id" ="p_bestil_1 "))->getPageId();
            $link_to_teleca re = $this->readPage(array ("mapr" ="byCode",
            "sql_id" ="p_telecare "))->getPageId();

            $this->obj_kurv = new Kurv($array, $link_to_basket );
            $this->obj_kurv->storeLinkBack( $_SERVER["HTTP_REFER ER"]);
            $this->obj_kurv->storeLinkToBes til($link_to_be stil);
            $this->obj_kurv->storeLinkToTel ecare($link_to_ telecare);
            $obj_kurv_go = $this->obj_kurv;
            }
            }
            $contents["gen_out"] = array($obj_kurv _go);


            Comment

            • tatsudoshi

              #7
              Re: Class variable problem

              Sorry for messing up the messages. I have never tryed using newsgroups
              before.
              Is it possible to delete a message from the group?


              Comment

              • tatsudoshi

                #8
                Re: Class variable problem

                I am not using references at all, as I have not been able to figure out how
                it works in the different versions of PHP.

                ----- Original Message -----
                From: "Colin Fine" <news@kindness. demon.co.uk>
                Newsgroups: comp.lang.php
                Sent: Monday, October 16, 2006 11:48 PM
                Subject: Re: Class variable problem

                You'll need to be more explicit about what you're expecting to see, and
                what you are seeing.
                >
                I thought it might be a problem with references (in PHP5 Objects are
                copied by references, but arrays are not) but I can't see a place where
                you're assigning to a copied array, so it doesn't appear to be that.
                >
                Colin

                Comment

                • tatsudoshi

                  #9
                  Re: Class variable problem

                  Your ansewer is message Re: Class variable problem : 17-10-2006 08:42
                  Sorry :-/

                  ----- Original Message -----
                  From: "Jerry Stuckle" <jstucklex@attg lobal.net>
                  Newsgroups: comp.lang.php
                  Sent: Tuesday, October 17, 2006 4:45 AM
                  Subject: Re: Class variable problem
                  The real question here is - how are you opening the object? Are you
                  creating a second object or are you referencing the existing object.
                  >
                  The code you're using to access it is also very important.
                  >
                  --
                  =============== ===
                  Remove the "x" from my email address
                  Jerry Stuckle
                  JDS Computer Training Corp.
                  jstucklex@attgl obal.net
                  =============== ===

                  Comment

                  • Jerry Stuckle

                    #10
                    Re: Class variable problem

                    tatsudoshi wrote:
                    Sorry for messing up the messages. I have never tryed using newsgroups
                    before.
                    Is it possible to delete a message from the group?
                    >
                    >
                    No, you can't delete a message from a newsgroup. It's on hundreds of
                    servers all over the world.

                    --
                    =============== ===
                    Remove the "x" from my email address
                    Jerry Stuckle
                    JDS Computer Training Corp.
                    jstucklex@attgl obal.net
                    =============== ===

                    Comment

                    • Jerry Stuckle

                      #11
                      Re: Class variable problem

                      tatsudoshi wrote:
                      ----- Original Message -----
                      From: "Jerry Stuckle" <jstucklex@attg lobal.net>
                      Newsgroups: comp.lang.php
                      Sent: Tuesday, October 17, 2006 4:45 AM
                      Subject: Re: Class variable problem
                      >
                      >
                      >>The real question here is - how are you opening the object? Are you
                      >>creating a second object or are you referencing the existing object.
                      >>
                      >>The code you're using to access it is also very important.
                      >>
                      >>--
                      >>============= =====
                      >>Remove the "x" from my email address
                      >>Jerry Stuckle
                      >>JDS Computer Training Corp.
                      >>jstucklex@att global.net
                      >>============= =====
                      >
                      >
                      Your ansewer is message Re: Class variable problem : 17-10-2006 08:42
                      Sorry :-/
                      >
                      >
                      (Top posting fixed)

                      Sorry, I don't see where you're showing the code you use to save and
                      restore the object. You indicate you're using the session, but that's
                      all. What's the actual code you're using?

                      This would be a lot easier if you could create a simplified case where
                      we could see exactly what you're trying to do. It's very difficult to
                      go through hundreds of lines of code to understand what someone else is
                      doing in a few minutes of spare time :-)

                      Also, a couple of tips. Please don't top post - this newsgroup uses
                      bottom posting (like this) or inline posting (responses mixed in and
                      immediately after the question) as a standard.

                      Also - I found the message you referenced. But I'm in a different time
                      zone. To me your message was posted at 2:42 AM.

                      --
                      =============== ===
                      Remove the "x" from my email address
                      Jerry Stuckle
                      JDS Computer Training Corp.
                      jstucklex@attgl obal.net
                      =============== ===

                      Comment

                      • tatsudoshi

                        #12
                        Re: Class variable problem


                        "Jerry Stuckle" <jstucklex@attg lobal.netskrev i en meddelelse
                        news:QYGdnYNb7b JeKanYnZ2dnUVZ_ uqdnZ2d@comcast .com...
                        tatsudoshi wrote:
                        >----- Original Message -----
                        >From: "Jerry Stuckle" <jstucklex@attg lobal.net>
                        >Newsgroups: comp.lang.php
                        >Sent: Tuesday, October 17, 2006 4:45 AM
                        >Subject: Re: Class variable problem
                        >>
                        >>
                        >>>The real question here is - how are you opening the object? Are you
                        >>>creating a second object or are you referencing the existing object.
                        >>>
                        >>>The code you're using to access it is also very important.
                        >>>
                        >>>--
                        >>>============ ======
                        >>>Remove the "x" from my email address
                        >>>Jerry Stuckle
                        >>>JDS Computer Training Corp.
                        >>>jstucklex@at tglobal.net
                        >>>============ ======
                        >>
                        >>
                        >Your ansewer is message Re: Class variable problem : 17-10-2006 08:42
                        >Sorry :-/
                        >>
                        >>
                        (Top posting fixed)
                        >
                        Sorry, I don't see where you're showing the code you use to save and
                        restore the object. You indicate you're using the session, but that's
                        all. What's the actual code you're using?
                        >
                        This would be a lot easier if you could create a simplified case where we
                        could see exactly what you're trying to do. It's very difficult to go
                        through hundreds of lines of code to understand what someone else is doing
                        in a few minutes of spare time :-)
                        >
                        Also, a couple of tips. Please don't top post - this newsgroup uses
                        bottom posting (like this) or inline posting (responses mixed in and
                        immediately after the question) as a standard.
                        >
                        Also - I found the message you referenced. But I'm in a different time
                        zone. To me your message was posted at 2:42 AM.
                        >
                        --
                        =============== ===
                        Remove the "x" from my email address
                        Jerry Stuckle
                        JDS Computer Training Corp.
                        jstucklex@attgl obal.net
                        =============== ===
                        I see. Thanks for the tips. I will make a simple example when I get home :-)


                        Comment

                        • Colin Fine

                          #13
                          Re: Class variable problem

                          tatsudoshi wrote:
                          ----- Original Message -----
                          From: "Colin Fine" <news@kindness. demon.co.uk>
                          Newsgroups: comp.lang.php
                          Sent: Monday, October 16, 2006 11:48 PM
                          Subject: Re: Class variable problem
                          >
                          >
                          >You'll need to be more explicit about what you're expecting to see, and
                          >what you are seeing.
                          >>
                          >I thought it might be a problem with references (in PHP5 Objects are
                          >copied by references, but arrays are not) but I can't see a place where
                          >you're assigning to a copied array, so it doesn't appear to be that.
                          >>
                          >Colin
                          >
                          >
                          (top-posting corrected)
                          I am not using references at all, as I have not been able to figure
                          out how
                          it works in the different versions of PHP.
                          >
                          No, I can see you aren't, and as far as I can see there is nowhere in
                          the code you posted where you should be.

                          If you had anything like

                          $row = $this->array[$index]

                          and then

                          $row[] = 2;

                          then you would need to make $row a reference otherwise the assignment to
                          a member of row would be to a copy and not to the original in $this->array.
                          This is true in both PHP4 and PHP5; but if the contents of
                          $this->array[$index] were itself an object (rather than an array), then
                          you would need to use a reference in PHP4, but not in PHP5.

                          You still haven't told us, AFAICS, precisely what result you are getting
                          and how it differs from what you expect.

                          Colin

                          Comment

                          • Rik

                            #14
                            Re: Class variable problem

                            Jerry Stuckle wrote:
                            tatsudoshi wrote:
                            >Sorry for messing up the messages. I have never tryed using
                            >newsgroups before.
                            >Is it possible to delete a message from the group?
                            >>
                            >>
                            >
                            No, you can't delete a message from a newsgroup. It's on hundreds of
                            servers all over the world.
                            Well, you can try to cancel the message, which will work with significant
                            delay on some servers, and then only for the users that haven't downloaded
                            it already. Confusion all around, it's a marvelous thing.

                            Grtz,
                            --
                            Rik Wasmus


                            Comment

                            • Jerry Stuckle

                              #15
                              Re: Class variable problem

                              Rik wrote:
                              Jerry Stuckle wrote:
                              >
                              >>tatsudoshi wrote:
                              >>
                              >>>Sorry for messing up the messages. I have never tryed using
                              >>>newsgroups before.
                              >>>Is it possible to delete a message from the group?
                              >>>
                              >>>
                              >>
                              >>No, you can't delete a message from a newsgroup. It's on hundreds of
                              >>servers all over the world.
                              >
                              >
                              Well, you can try to cancel the message, which will work with significant
                              delay on some servers, and then only for the users that haven't downloaded
                              it already. Confusion all around, it's a marvelous thing.
                              >
                              Grtz,
                              Rik,

                              Unfortunately, very few servers process cancel requests any more. It's
                              too easy to fake it and cancel someone else's post.

                              --
                              =============== ===
                              Remove the "x" from my email address
                              Jerry Stuckle
                              JDS Computer Training Corp.
                              jstucklex@attgl obal.net
                              =============== ===

                              Comment

                              Working...