1. Which version of PHP introduced the static keyword?
a) PHP 4
b) PHP 5
c) PHP 5.2
d) PHP 5.3
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)?
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.
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?
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
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
7. Which keyword is used to declare a constant property?
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
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
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?
Explanation:All scalar data i.e boolean, integer, float and string can be contained in constants.
Sanfoundry Global Education & Learning Series – PHP Programming.
To practice all questions on PHP Programming, here is complete set of 250+ Multiple Choice Questions and Answers on PHP.