PHP Questions and Answers Part-5

1. How many validation filters like FILTER_VALIDATE_EMAIL are currently available?
a) 5
b) 6
c) 7
d) 8

Answer: c

2. Which function initializes the constants necessary for using the openlog(), clodelog(), and syslog() functions?
a) log_variable()
b) define_variable()
c) define_log_variable()
d) define_syslog_variable()

Answer: d
Explanation: If you’re running PHP version 5.2.X or older, you need to execute this function before using any of the following logging functions.

3. Which variable is used to collect form data sent with both the GET and POST methods?
a) $BOTH
b) $_BOTH

Answer: d
Explanation: In PHP the global variable $_REQUEST is used to collect data after submitting an HTML form.

4. Objects are defined as instances of user defined classes that can hold ____________?
a) values
b) functions
c) both values and functions
d) None of the above

Answer: c
Explanation: Objects are defined as instances of user-defined classes that can hold both values and functions.

5. Which function is used to remove all HTML tags from a string passed to a form?
a) remove_tags()
b) strip_tags()
c) tags_strip()
d) tags_remove()

Answer: b
Explanation: The function strip_tags() is used to strip a string from HTML, XML, and PHP tags.

6. You can extend the exception base class, but you cannot override any of the preceding methods because they are declared as_______.
a) final
b) static
c) private
d) protected

Answer: a
Explanation: Marking a method as final prevents it from being overridden by a subclass.

7. How many methods are available for the exception class?
a) 5
b) 6
c) 7
d) 8

Answer: c
Explanation: The seven methods are: getCode(), getFile(), getLine(), getMessage(), getPrevious(), getTrace(), getTraceAsString().

8. How many compound data types are available in php?
a) 1
b) 2
c) 3
d) 4

Answer: c
Explanation: The first five are called simple data types and the last three are compound data types.

9. Which two predefined variables are used to retrieve information from forms?
a) $GET & $SET
b) $_GET & $_SET
c) $__GET & $__SET
d) GET & SET

Answer: b
Explanation: The global variables $_GET is used to collect form data after submitting an HTML form with the method=”get”. The variable $_SET is also used to retrieve information from forms.

10. PHP is a __________ language?
a) user-side scripting
b) client-side scripting
c) server-side scripting
d) Both B and C

Answer: c
Explanation: PHP is a server-side scripting language designed specifically for web development.