Câu hỏi phỏng vấn PHP
Câu hỏi

How to turn errors in...

Câu trả lời

Here's how you can turn errors into exceptions in PHP:

Using set_error_handler()

  1. Create a custom error handling function that throws an exception:
php Copy
function errorHandler($errno, $errstr, $errfile, $errline) {
    throw new Exception("Error: $errstr in $errfile on line $errline", $errno);
}
  1. Set the custom error handler using set_error_handler():
php Copy
set_error_handler('errorHandler');
  1. Now, any errors that occur will be thrown as exceptions.

Using ErrorException class

  1. Enable error reporting to throw exceptions:
php Copy
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
  1. Use the ErrorException class to throw exceptions for specific error level...
senior

senior

Gợi ý câu hỏi phỏng vấn

entry

What is the use of ini_set() ?

junior

How is it possible to set an infinite execution time for PHP script?

junior

What is the difference between single-quoted and double-quoted strings in PHP?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào