PHP Questions and Answers Part-14

1. How many error levels are available in PHP?
a) 14
b) 15
c) 16
d) 17

Answer: c
Explanation: Whenever the PHP engine encounters any problem that prevents a script from running properly it generates an error message. There are sixteen error levels and each level is represented by an integer value and an associated constant.

2. What is the description of Error level E_ERROR?
a) Fatal run-time error
b) Near-fatal error
c) Compile-time error
d) Fatal Compile-time error

Answer: a
Explanation: E_ERROR is a fatal run-time error, that can’t be recovered from and the execution of the script is stopped immediately.

3. Which version of PHP introduced E_STRICT Error level?
a) PHP 4
b) PHP 5
c) PHP 5.2
d) PHP 5.3

Answer: b
Explanation: E_STRICT is PHP version portability suggestions. It is not strictly an error, but it is triggered whenever PHP encounters code that could lead to problems or forward incompatibilities.

4. Which character does 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.

5. Say you want to report error concerned about fatal run-time, fatal compile-time error and core error which statement would you use?
a) error_reporting = E_ALL
b) error_reporting = E_ERROR | E_PARSE | E_CORE_ERROR
c) error_reporting = E_ERROR | E_COMPILE_WARNING | E_CORE_ERROR
d) error_reporting = E_ERROR | E_COMPILE_ERROR | E_CORE_ERROR

Answer: d
Explanation: E_ERROR is a fatal run-time error, that can’t be recovered from. E_COMPILE_ERROR is a fatal error that occurs while the script was being compiled. And E_CORE_ERROR is a fatal error that occurs during the PHP’s engine initial startup.

6. Which version introduced the function error_get_last()?
a) PHP 4
b) PHP 5
c) PHP 5.2
d) PHP 5.3

Answer: c
Explanation: This function returns an associative array consisting of the type, message, file, and line of the last occurring error.

7. Which of the following statements causes PHP to disregard repeated error messages that occur within the same file and on the same line?
a) ignore_repeated_errors
b) ignore_repeat_error
c) repeatedly_ignore_error
d) repeated_error_ignore

Answer: a
Explanation: ignore_repeated_errors will not log repeated messages. The repeated errors must occur in the same file on the same line unless ignore_repeated_source is set to true.

8. Which function initializes the constants necessary for using the openlog(), clodelog(), and syslog() functions?
a) define_variable()
b) define_log_variable()
c) 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.

9. Which logging option’s description is if an error occurs when writing to the syslog, send output to the system console?

Answer: a
Explanation: If there is an error while sending data to the system logger, LOG_CONS will write directly to the system console.

10. Which function is responsible for sending a custom message to the system log?
a) systemlog()
b) syslog()
c) log_system()
d) sys_log()

Answer: b
Explanation: The function syslog() generates a log message that will be distributed by the system logger.