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

senior

Compare MySQLi or PDO - what are the pros and cons?

middle

Explain function call by reference

junior

Explain what the different PHP errors are

Bình luận

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

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