PHP Questions & Answers – Error Handling

PHP Multiple Choice Questions & Answers (MCQs) focuses on “Error Handling”.

Q 1. How many error levels are available in PHP?
A. 14
B. 15
C. 16
D. 17

Show Answer Answer:-C. 16
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.


Q 2. What is the description of Error level E_ERROR?
A. Near-fatal error
B. Fatal run-time error
C. Compile-time error
D. Fatal Compile-time error

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


Q 3. Which version of PHP introduced E_STRICT Error level?
A. PHP 4
B. PHP 5
C. PHP 5.2
D. PHP 5.3

Show Answer Answer:-B. PHP 5
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.


Q 4. Which character does the error_reporting directive use to represent the logical operator NOT?
A. /
B. !
C. ~
D. ^

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


Q 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_ERROR | E_CORE_ERROR
D. error_reporting = E_ERROR | E_COMPILE_WARNING | E_CORE_ERROR

Show Answer Answer:-C. error_reporting = E_ERROR | E_COMPILE_ERROR | E_CORE_ERROR
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.

Q 6. Which version introduced the function error_get_last()?
A. PHP 4
B. PHP 5
C. PHP 5.2
D. PHP 5.3

Show Answer Answer:-C. PHP 5.2
Explanation This function returns an associative array consisting of the type, message, file, and line of the last occurring error.


Q 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

Show Answer Answer:-A. ignore_repeated_errors
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.


Q 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()

Show Answer Answer:-D. define_syslog_variable()
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.


Q 9. Which logging option’s description is if an error occurs when writing to the syslog, send output to the system console?
A. LOG_CONS
B. LOG_NDELAY
C. LOG_ODELAY
D. LOG_PERROR

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


Q 10. Which function is responsible for sending a custom message to the system log?
A. systemlog()
B. syslog()
C. log_system()
D. sys_log()

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

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

You cannot copy content of this page