PHP Questions & Answers – Error Handling

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

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

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
View Answer

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
View Answer

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.
advertisement
advertisement

4. Which character does the error_reporting directive use to represent the logical operator NOT?
a) /
b) !
c) ~
d) ^
View Answer

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
View Answer

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.
Note: Join free Sanfoundry classes at Telegram or Youtube

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

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
View Answer

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.
advertisement

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()
View Answer

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?
a) LOG_CONS
b) LOG_NDELAY
c) LOG_ODELAY
d) LOG_PERROR
View Answer

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

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

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

Sanfoundry Global Education & Learning Series – PHP Programming.

To practice all questions on PHP Programming, here is complete set of 1000+ Multiple Choice Questions and Answers on PHP.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.