PHP Multiple Choice Questions – Object Advanced Features

This set of PHP Multiple Choice Questions & Answers (MCQs) focuses on “Object Advanced Features”.

1. Which version of PHP introduced the static keyword?
a) PHP 4
b) PHP 5
c) PHP 5.2
d) PHP 5.3
View Answer

Answer: b
Explanation: The static keyword was introduced with PHP 5. It cannot be used in PHP 4 scripts.

2. Which keyword is used to access a static method or property from within the same class(rather than from child)?
a) static
b) strat
c) self
d) set
View Answer

Answer: c
Explanation: Self is to classes what the $this pseudo-variable is to objects.

3. In which of the following circumstance should you use a static reference to a non static method?
a) Making a method call using parent
b) Making a method call using child
c) Making an object call using parent
d) Making an object call using child
View Answer

Answer: a
Explanation: Making a method call using parent is the only circumstance in which you should use a static reference to a non-static method.
advertisement
advertisement

4. Which one of the following variable cannot be used inside a static method?
a) $this
b) $get
c) $set
d) $date
View Answer

Answer: a
Explanation: By definition, static methods are not invoked in the context of an object. For this reason, static methods and properties are often referred to as class variables and properties.

5. What does PDO stand for?
a) PHP Data Orientation
b) PHP Database Object
c) PHP Database Orientation
d) PHP Data Object
View Answer

Answer: d
Explanation: The PDO class provides a common interface to different database applications.

6. Which version of PHP allows you to define constant properties within a class?
a) PHP 4
b) PHP 4.1
c) PHP 4.3
d) PHP 5
View Answer

Answer: d
Explanation: None.

7. Which keyword is used to declare a constant property?
a) const
b) con
c) constant
d) _constant
View Answer

Answer: a
Explanation: A constant property is declared with the const keyword. Like global constants, class constants cannot be changed once they are set.
advertisement

8. Which one of the following is a constant variable?
a) const $name
b) const $NAME
c) constant NAME
d) const NAME
View Answer

Answer: d
Explanation: Constants are not prefixed with a dollar sign like regular properties. By convention, they are often named using only uppercase characters

9. What will happen if you try to set a value to a constant once it has been declared?
a) The value of the variable will change
b) The value of the variable will not change
c) Parse Error
d) Nothing
View Answer

Answer: c
Explanation: You should use constants when your property needs to be available across all instances of a class, and when the property value needs to be fixed and unchanging.
advertisement

10. How many of the following can be contained in constants?

i) boolean
ii) integer
iii) float
iv)  string

a) 1
b) 2
c) 3
d) 4
View Answer

Answer: d
Explanation: All scalar data i.e boolean, integer, float and string can be contained in constants.

More MCQs on PHP Object Advanced Features:

Sanfoundry Global Education & Learning Series – PHP Programming.

To practice all questions on PHP Programming, here is complete set of 1000+ Multiple Choice Questions and Answers on PHP.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.