PHP Exam Question ( multiple choice )

Posted on 2011-04-26
Last Modified: 2012-05-11
Hello experts , I found this Question in an exam ,
( multiple choice )
Please explain your ANSWER .
You need to keep an eye on the existing number of objects of a given class without introducing a non-class member variable. Which of the following makes this happen?

       a.       Add a member variable that gets incremented in the default constructor and decremented in the destructor  
       b.       Add a local variable that gets incremented in each constructor and decremented in the destructor
       c.       Add a static member variable that gets incremented in each constructor and decremented in the destructor
       d.       This cannot be accomplished since the creation of objects is being done dynamically via "new."  
Question by:honestman31
    LVL 82

    Assisted Solution

    Well, giving you the direct answer would just be a "crime". So here's a hint:

    >>without introducing a non-class member variable.
    That rules out "b".

    So if you know what a member variable and a static variable is, then you would know that it is definitely NOT "d".

    So, lookup what is a "member variable" and a "static variable" in Object-Oriented Programming (OOP). You'll know the answer once you look these up.
    LVL 12

    Accepted Solution

    > existing number of objects of a given class.

    The answer is definitely "A".

    Since you have number of objects, the variable can't be static, static is variable that let you access it directly from the class without having to create instance (ex: myClass::staticVarName).

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now