PHP Questions and Answers Part-3

1. Which keyword is used to refer to properties or methods within the class itself?
a) Private
b) public
c) Protected
d) this

Answer: d
Explanation: this keyword is used to refer to properties or methods within the class itself.

2. Which character do the error_reporting directive use to represent the logical operator NOT?
a) /
b) !
c) ~
d) ^

Answer: c
Explanation: The twidle (~) character is used to represent the logical operator NOT.

3. Which one of the following functions is used to determine whether a class exists?
a) exist()
b) __exist()
c) class_exist()
d) exist_class()

Answer: c
Explanation: The class_exist() function returns true or false according to whether the class exists within the currently executing script content.

4. POSIX stands for
a) Portable Operating System Interface for Unix
b) Portable Operating System Interface for Linux
c) Portative Operating System Interface for Unix
d) Portative Operating System Interface for Linux

Answer: a
Explanation: Portable Operating System Interface for Unix

5. PHP recognizes constructors by the name.
a) classname()
b) _construct()
c) function_construct()
d) function__construct()

Answer: d
Explanation: A double underscore followed by the construct keyword. Its syntax is function__construct ([ argument1, argument2,.....]) { Class Initialization code }

6. What does SPL stand for?
a) Standard PHP Library
b) Source PHP Library
c) Standard PHP List
d) Source PHP List

Answer: a
Explanation: The standard PHP library(SPL) extends PHP by offering ready-made solutions to common place tasks such as file access, iteration of various sorts etc.

7. Class is a programmer-defined data type, which includes _____ methods and ______ variable?
a) local, global
b) global, global
c) global, local
d) local, local

Answer: d
Explanation: Class is a programmer-defined data type, which includes local methods and local variables.

8. If $a = 12 what will be returned when ($a == 12) ? 5 : 1 is executed?
a) 12
b) 1
c) Error
d) 5

Answer: d
Explanation: ?: is known as ternary operator. If condition is true then the part just after the ? is executed else the part after : .

9. Which version of PHP introduced the instanceof keyword?
a) PHP 4
b) PHP 5
c) PHP 5.3
d) PHP 6

Answer: b
Explanation: Using instanceof keyword we can determine whether an object is an instance of a class. $manager = new Employee() … if ($manager instanceof Employee) echo “True”;

10. Which one of the following keyword is used to inherit our subclass into a superclass?
a) extends
b) implements
c) inherit
d) include

Answer: a
Explanation: When we extend a class then the subclass will inherit all the public and protected methods from the parent class. The keyword implements are used with interfaces. With inheritance, we use the keyword extends.