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
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
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
Explanation: Making a method call using parent is the only circumstance in which you should use a static reference to a non-static method.
4. Which one of the following variable cannot be used inside a static method?
a) $this
b) $get
c) $set
d) $date
View Answer
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
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
Explanation: None.
7. Which keyword is used to declare a constant property?
a) const
b) con
c) constant
d) _constant
View Answer
Explanation: A constant property is declared with the const keyword. Like global constants, class constants cannot be changed once they are set.
8. Which one of the following is a constant variable?
a) const $name
b) const $NAME
c) constant NAME
d) const NAME
View Answer
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
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.
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
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.
- Practice MCA MCQs
- Check MCA Books
- Check PHP Books
- Apply for Programming Internship
- Check Information Technology Books