By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,890 Members | 1,048 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,890 IT Pros & Developers. It's quick & easy.

keep track how many object in PHP4

P: n/a
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!
Sep 4 '08 #1
Share this Question
Share on Google+
11 Replies


P: n/a
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.
Sep 4 '08 #2

P: n/a
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.
Sep 4 '08 #3

P: n/a

"Ivan Sanchez Ortega" <ivansanchez-alg@rroba-escomposlinux.-.punto.-.org>
/ : news:g9**********@hercules.cohp1...
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.
Sep 4 '08 #4

P: n/a

Andrew G. Koptyaev schreef:
"Ivan Sanchez Ortega" <ivansanchez-alg@rroba-escomposlinux.-.punto.-.org>
/ : news:g9**********@hercules.cohp1...
>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/
============================
Sep 4 '08 #5

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

http://php.net/oop5
--
----------------------------------
Iván Sánchez Ortega -ivan-algarroba-sanchezortega-punto-es-

Tea. Earl grey. Hot.
-- Captain Jean-Luc Picard, from Star Trek.
Sep 4 '08 #6

P: n/a
On Sep 4, 7:03*pm, Ivn Snchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
Andrew G. Koptyaev wrote:
Please point me to corresponding article onwww.php.net

Here you are:

http://php.net/oop5

--
----------------------------------
Ivn Snchez 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 :)
Sep 5 '08 #7

P: n/a
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.

<jo*************@googlemail.com???????/???????? ? ???????? ?????????:
news:56**********************************@y38g2000 hsy.googlegroups.com...
On Sep 4, 7:03 pm, Ivn Snchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
Andrew G. Koptyaev wrote:
Please point me to corresponding article onwww.php.net

Here you are:

http://php.net/oop5

--
----------------------------------
Ivn Snchez 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 :)
Sep 5 '08 #8

P: n/a

"C. (http://symcbean.blogspot.com/)" <co************@gmail.com>
???????/???????? ? ???????? ?????????:
news:18**********************************@25g2000p rz.googlegroups.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.
Sep 5 '08 #9

P: n/a

"Erwin Moller"
<Si******************************************@spam yourself.com>
???????/???????? ? ???????? ?????????:
news:48*********************@news.xs4all.nl...
>
Andrew G. Koptyaev schreef:
>"Ivan Sanchez Ortega" <ivansanchez-alg@rroba-escomposlinux.-.punto.-.org>
/ :
news:g9**********@hercules.cohp1...
>>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
I think I can't track instance because I can't share one variable between
instance. All member variables belong corresponding object.
Sep 5 '08 #10

P: n/a
Andrew G. Koptyaev wrote:
"C. (http://symcbean.blogspot.com/)" <co************@gmail.com>
???????/???????? ? ???????? ?????????:
news:18**********************************@25g2000p rz.googlegroups.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.
js*******@attglobal.net
==================

Sep 5 '08 #11

P: n/a
Andrew G. Koptyaev wrote:
"Erwin Moller"
<Si******************************************@spam yourself.com>
???????/???????? ? ???????? ?????????:
news:48*********************@news.xs4all.nl...
>Andrew G. Koptyaev schreef:
>>"Ivan Sanchez Ortega" <ivansanchez-alg@rroba-escomposlinux.-.punto.-.org>
/ :
news:g9**********@hercules.cohp1...
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

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.
js*******@attglobal.net
==================

Sep 5 '08 #12

This discussion thread is closed

Replies have been disabled for this discussion.