keep track how many object in PHP4

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew G. Koptyaev

    keep track how many object in PHP4

    Please help.

    I need to keep track of how many object of a given class without introducing
    a non-class member variable. Which one of the following will allow me to do
    this?

    1) Add member variable that gets incremented in the default constructor and
    decremented in the destructor.
    2) Add local variable that gets incremented in the each constructor and
    decremented in the destructor.
    3) Add static member variable that gets incremented in the each constructor
    and
    decremented in the destructor.
    4) This cannot be accomplished since the creation of objects is being done
    dynamically via "new".

    Thank you!


  • C. (http://symcbean.blogspot.com/)

    #2
    Re: keep track how many object in PHP4

    On 4 Sep, 17:22, "Andrew G. Koptyaev" <kopty...@gmail .comwrote:
    Please help.
    >
    I need to keep track of how many object of a given class without introducing
    a non-class member variable. Which one of the following will allow me to do
    this?
    >
    1) Add member variable that gets incremented in the default constructor and
    decremented in the destructor.
    2) Add local variable that gets incremented in the each constructor and
    decremented in the destructor.
    3) Add static member variable that gets incremented in the each constructor
    and
    decremented in the destructor.
    4) This cannot be accomplished since the creation of objects is being done
    dynamically via "new".
    >
    Thank you!
    Thank you for posting your homework / interview quiz here.

    The correct answer is none of the above: use a factory to control
    creation / destruction.

    C.

    Comment

    • =?UTF-8?B?SXbDoW4gU8OhbmNoZXogT3J0ZWdh?=

      #3
      Re: keep track how many object in PHP4

      Andrew G. Koptyaev wrote:
      I need to keep track of how many object of a given class without
      introducing a non-class member variable. Which one of the following will
      allow me to do this?
      Since this is obviously a question from a test, the correct answer
      is "study".

      --
      ----------------------------------
      Iván Sánchez Ortega -ivan-algarroba-sanchezortega-punto-es-

      "Los periódicos tradicionales ya están muertos (...) quieren dominar algo
      que se les ha escapado de las manos. Tienen miedo de sus propias webs."
      -- Gumersindo Lafuente, ex-director de Elmundo.es.

      Comment

      • Andrew G. Koptyaev

        #4
        Re: keep track how many object in PHP4


        "Ivan Sanchez Ortega" <ivansanchez-alg@rroba-escomposlinux.-.punto.-.org>
        ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ: news:g9p2uu$2t1 $1@hercules.coh p1...
        Andrew G. Koptyaev wrote:
        >
        >I need to keep track of how many object of a given class without
        >introducing a non-class member variable. Which one of the following will
        >allow me to do this?
        >
        Since this is obviously a question from a test, the correct answer
        is "study".
        Please point me to corresponding article on www.php.net
        Thank you.


        Comment

        • Erwin Moller

          #5
          Re: keep track how many object in PHP4


          Andrew G. Koptyaev schreef:
          "Ivan Sanchez Ortega" <ivansanchez-alg@rroba-escomposlinux.-.punto.-.org>
          ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ: news:g9p2uu$2t1 $1@hercules.coh p1...
          >Andrew G. Koptyaev wrote:
          >>
          >>I need to keep track of how many object of a given class without
          >>introducing a non-class member variable. Which one of the following will
          >>allow me to do this?
          >Since this is obviously a question from a test, the correct answer
          >is "study".
          >
          Please point me to corresponding article on www.php.net
          Thank you.
          Andrew,

          You won't find an article on www.php.net describing this excact question.
          It is like asking where on www.php.net you can find the answer to the
          question: "How do I print 'dog' to the browser?".
          You will find print and echo commands, but (probably) not:
          echo "dog";

          You can easily answer this question if you understand the difference
          between instances and classes.
          That is why Ivan advised you study a bit more, which is good advise.
          Best of luck!

          Regards,
          Erwin Moller

          --
          =============== =============
          Erwin Moller
          Now dropping all postings from googlegroups.
          Why? http://improve-usenet.org/
          =============== =============

          Comment

          • =?UTF-8?B?SXbDoW4gU8OhbmNoZXogT3J0ZWdh?=

            #6
            Re: keep track how many object in PHP4

            Andrew G. Koptyaev wrote:
            Please point me to corresponding article on www.php.net
            Here you are:




            --
            ----------------------------------
            Iván Sánchez Ortega -ivan-algarroba-sanchezortega-punto-es-

            Tea. Earl grey. Hot.
            -- Captain Jean-Luc Picard, from Star Trek.

            Comment

            • johannes.heinen@googlemail.com

              #7
              Re: keep track how many object in PHP4

              On Sep 4, 7:03 pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
              escomposlinux.-.punto.-.orgwrote:
              Andrew G. Koptyaev wrote:
              Please point me to corresponding article onwww.php.net
              >
              Here you are:
              >

              >
              --
              ----------------------------------
              Iván Sánchez Ortega -ivan-algarroba-sanchezortega-punto-es-
              >
              Tea. Earl grey. Hot.
                                              -- Captain Jean-Luc Picard, from Star Trek.
              Hi,

              the correct answer should be "(static) class variable" (not object
              variable). You can easily increment this static variable in your
              instance constructor. so you don't need any factory or other "more
              complex" design patterns.

              But your question really belongs to the very very low level basics of
              object oriented concepts, so better read a school book about it (every
              java for dummies handbook should do).

              Have fun :)

              Comment

              • Andrew G. Koptyaev

                #8
                Re: keep track how many object in PHP4

                Other word true is:

                3) Add static member variable that gets incremented in the each constructor
                and decremented in the destructor.

                But it is php4 and no desctructor in language.

                <johannes.heine n@googlemail.co m???????/???????? ? ???????? ?????????:
                news:563906e8-3349-4415-ba2a-86876d4a0d47@y3 8g2000hsy.googl egroups.com...
                On Sep 4, 7:03 pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
                escomposlinux.-.punto.-.orgwrote:
                Andrew G. Koptyaev wrote:
                Please point me to corresponding article onwww.php.net
                >
                Here you are:
                >

                >
                --
                ----------------------------------
                Iván Sánchez Ortega -ivan-algarroba-sanchezortega-punto-es-
                >
                Tea. Earl grey. Hot.
                -- Captain Jean-Luc Picard, from Star Trek.
                Hi,

                the correct answer should be "(static) class variable" (not object
                variable). You can easily increment this static variable in your
                instance constructor. so you don't need any factory or other "more
                complex" design patterns.

                But your question really belongs to the very very low level basics of
                object oriented concepts, so better read a school book about it (every
                java for dummies handbook should do).

                Have fun :)


                Comment

                • Andrew G. Koptyaev

                  #9
                  Re: keep track how many object in PHP4


                  "C. (http://symcbean.blogsp ot.com/)" <colin.mckinnon @gmail.com>
                  ???????/???????? ? ???????? ?????????:
                  news:1820ad3e-eeea-420c-9a50-5edf63f3f3c0@25 g2000prz.google groups.com...
                  On 4 Sep, 17:22, "Andrew G. Koptyaev" <kopty...@gmail .comwrote:
                  >Please help.
                  >>
                  >I need to keep track of how many object of a given class without
                  >introducing
                  >a non-class member variable. Which one of the following will allow me to
                  >do
                  >this?
                  >>
                  >1) Add member variable that gets incremented in the default constructor
                  >and
                  >decremented in the destructor.
                  >2) Add local variable that gets incremented in the each constructor and
                  >decremented in the destructor.
                  >3) Add static member variable that gets incremented in the each
                  >constructor
                  >and
                  >decremented in the destructor.
                  >4) This cannot be accomplished since the creation of objects is being
                  >done
                  >dynamically via "new".
                  >>
                  >Thank you!
                  >
                  Thank you for posting your homework / interview quiz here.
                  >
                  The correct answer is none of the above: use a factory to control
                  creation / destruction.
                  >
                  C.
                  It is from test with one true. I must select one.


                  Comment

                  • Andrew G. Koptyaev

                    #10
                    Re: keep track how many object in PHP4


                    "Erwin Moller"
                    <Since_humans_r ead_this_I_am_s pammed_too_much @spamyourself.c om>
                    ???????/???????? ? ???????? ?????????:
                    news:48c014a0$0 $184$e4fe514c@n ews.xs4all.nl.. .
                    >
                    Andrew G. Koptyaev schreef:
                    >"Ivan Sanchez Ortega" <ivansanchez-alg@rroba-escomposlinux.-.punto.-.org>
                    >ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
                    >news:g9p2uu$2t 1$1@hercules.co hp1...
                    >>Andrew G. Koptyaev wrote:
                    >>>
                    >>>I need to keep track of how many object of a given class without
                    >>>introducin g a non-class member variable. Which one of the following
                    >>>will
                    >>>allow me to do this?
                    >>Since this is obviously a question from a test, the correct answer
                    >>is "study".
                    >>
                    >Please point me to corresponding article on www.php.net
                    >Thank you.
                    >
                    Andrew,
                    >
                    You won't find an article on www.php.net describing this excact question.
                    It is like asking where on www.php.net you can find the answer to the
                    question: "How do I print 'dog' to the browser?".
                    You will find print and echo commands, but (probably) not:
                    echo "dog";
                    >
                    You can easily answer this question if you understand the difference
                    between instances and classes.
                    That is why Ivan advised you study a bit more, which is good advise.
                    Best of luck!
                    >
                    Regards,
                    Erwin Moller
                    I think I can't track instance because I can't share one variable between
                    instance. All member variables belong corresponding object.


                    Comment

                    • Jerry Stuckle

                      #11
                      Re: keep track how many object in PHP4

                      Andrew G. Koptyaev wrote:
                      "C. (http://symcbean.blogsp ot.com/)" <colin.mckinnon @gmail.com>
                      ???????/???????? ? ???????? ?????????:
                      news:1820ad3e-eeea-420c-9a50-5edf63f3f3c0@25 g2000prz.google groups.com...
                      >On 4 Sep, 17:22, "Andrew G. Koptyaev" <kopty...@gmail .comwrote:
                      >>Please help.
                      >>>
                      >>I need to keep track of how many object of a given class without
                      >>introducing
                      >>a non-class member variable. Which one of the following will allow me to
                      >>do
                      >>this?
                      >>>
                      >>1) Add member variable that gets incremented in the default constructor
                      >>and
                      >>decremented in the destructor.
                      >>2) Add local variable that gets incremented in the each constructor and
                      >>decremented in the destructor.
                      >>3) Add static member variable that gets incremented in the each
                      >>constructor
                      >>and
                      >>decremented in the destructor.
                      >>4) This cannot be accomplished since the creation of objects is being
                      >>done
                      >>dynamically via "new".
                      >>>
                      >>Thank you!
                      >Thank you for posting your homework / interview quiz here.
                      >>
                      >The correct answer is none of the above: use a factory to control
                      >creation / destruction.
                      >>
                      >C.
                      >
                      It is from test with one true. I must select one.
                      >
                      >
                      >
                      Study up on the basics of OO design.

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

                      Comment

                      • Jerry Stuckle

                        #12
                        Re: keep track how many object in PHP4

                        Andrew G. Koptyaev wrote:
                        "Erwin Moller"
                        <Since_humans_r ead_this_I_am_s pammed_too_much @spamyourself.c om>
                        ???????/???????? ? ???????? ?????????:
                        news:48c014a0$0 $184$e4fe514c@n ews.xs4all.nl.. .
                        >Andrew G. Koptyaev schreef:
                        >>"Ivan Sanchez Ortega" <ivansanchez-alg@rroba-escomposlinux.-.punto.-.org>
                        >>ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
                        >>news:g9p2uu$2 t1$1@hercules.c ohp1...
                        >>>Andrew G. Koptyaev wrote:
                        >>>>
                        >>>>I need to keep track of how many object of a given class without
                        >>>>introduci ng a non-class member variable. Which one of the following
                        >>>>will
                        >>>>allow me to do this?
                        >>>Since this is obviously a question from a test, the correct answer
                        >>>is "study".
                        >>Please point me to corresponding article on www.php.net
                        >>Thank you.
                        >Andrew,
                        >>
                        >You won't find an article on www.php.net describing this excact question.
                        >It is like asking where on www.php.net you can find the answer to the
                        >question: "How do I print 'dog' to the browser?".
                        >You will find print and echo commands, but (probably) not:
                        >echo "dog";
                        >>
                        >You can easily answer this question if you understand the difference
                        >between instances and classes.
                        >That is why Ivan advised you study a bit more, which is good advise.
                        >Best of luck!
                        >>
                        >Regards,
                        >Erwin Moller
                        >
                        I think I can't track instance because I can't share one variable between
                        instance. All member variables belong corresponding object.
                        >
                        >
                        >
                        Erwin is correct. You can if you understand the difference between
                        instances and classes.

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

                        Comment

                        Working...