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

middle

What is the difference between using self and $this ?

middle

When should I use require_once vs require ?

expert

Are PDO prepared statements sufficient to prevent SQL injection?

Bình luận

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

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