473,830 Members | 2,268 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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!
Sep 4 '08 #1
11 2767
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
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

"Ivan Sanchez Ortega" <ivansanchez-alg@rroba-escomposlinux.-.punto.-.org>
ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ: news:g9******** **@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.
Sep 4 '08 #4

Andrew G. Koptyaev schreef:
"Ivan Sanchez Ortega" <ivansanchez-alg@rroba-escomposlinux.-.punto.-.org>
ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ: news:g9******** **@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/
=============== =============
Sep 4 '08 #5
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
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:

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.
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
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.co m???????/???????? ? ???????? ?????????:
news:56******** *************** ***********@y38 g2000hsy.google groups.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:

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.
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

"C. (http://symcbean.blogsp ot.com/)" <co************ @gmail.com>
???????/???????? ? ???????? ?????????:
news:18******** *************** ***********@25g 2000prz.googleg roups.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

"Erwin Moller"
<Si************ *************** *************** @spamyourself.c om>
???????/???????? ? ???????? ?????????:
news:48******** *************@n ews.xs4all.nl.. .
>
Andrew G. Koptyaev schreef:
>"Ivan Sanchez Ortega" <ivansanchez-alg@rroba-escomposlinux.-.punto.-.org>
ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
news:g9******* ***@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.
Sep 5 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3268
by: Chung Leong | last post by:
Help me here. I've become a bitconfused about how PHP4 deals with objects after reading this description of PHP5: "PHP's handling of objects has been completely rewritten, allowing for better performance and more features. In previous versions of PHP, objects were handled like primitive types (for instance integers and strings). The drawback of this method was that semantically the whole object was copied when a variable was assigned, or...
12
2141
by: Berislav Lopac | last post by:
Is there a way for an object to unset itself in PHP4? Of course I could unset it from outside, but I would like to keep the code clean. The object has a method which deletes it's "footprint" in the database, and as the idea is that we don't need the object once itsin't in the DB it would be nice if the same method could get rid of the PHP object iself as well. Berislav
11
9289
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in C++. I find my self sometimes, trying Object app = Object(); Object *app = Object(); Object app = new Object();
8
2496
by: Dica | last post by:
i've got a client that wants to be able to review records about IIS generated emails. in his own words, he wants the "ability to track and report message status (i.e. how many messages were sent successfully, how many were blocked, how many bounced back with an incorrect address)" i'd start by adding a new row containing the email address, dateTime, etc when first sending the email, but how to track the rest of the info? for...
3
2260
by: RR | last post by:
We have cards that are numbered consecutively. These cards are given out to different people in different sized batches. One group might get 5, the next group might get 20. What is a good way to set up to keep track of which numbered cards are given out, and to who?
3
2916
by: Alan Wang | last post by:
Hi there, Once my application gets complicated and complicated. I found it's really hard to keep track of Session value I am using in my asp.net application. I am just wondering if anyone have any experience on how to keep track of session value. Any help it's appreciated. Thanks Alan
5
4044
by: Daniel Walzenbach | last post by:
Hi, I need to track all changes made to an object. Consider the following class: Public Class Dog
15
6728
by: l3vi | last post by:
I have a new system Im building that stores entries of what people are searching for on my sites. I want to be able to keep records of how many times a keyword was searched for daily, and from that I can calculate weekly and monthly. At this point I have one entry per search phrase with the number of hits the search phrase has gotten, and the last time it was updated. As I start to take the program out of testing and move in more...
19
1387
by: art | last post by:
Hi, I am running PHP 4.3.9 and Apache 2.0.52. This is the error: an unknown filter was not added: PHP I've read over 40 suggestions with no luck. Can anyone help? I am running Cent-OS. does anyone need to see my config files? Anything would help....
0
9790
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10770
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10199
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9312
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7741
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6948
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5779
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3956
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3074
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.