Bird
0
0

What is wrong with this error handler function?

medium📝 Debug Q7 of 15
PHP - Error and Exception Handling
What is wrong with this error handler function?
function handler($errno, $errstr) {
  echo "Error: $errstr";
  return 1;
}
set_error_handler('handler');
Aset_error_handler requires a closure, not a named function.
BReturn value should be boolean, not integer.
CEchoing error message is not allowed in handler.
DFunction must accept four parameters.
Step-by-Step Solution
Solution:
  1. Step 1: Check the return type expected from error handlers

    Custom error handlers should return true or false (boolean), not integers.
  2. Step 2: Validate other options

    Accepting two parameters is allowed, echoing is allowed, and named functions are valid.
  3. Final Answer:

    Return value should be boolean, not integer. -> Option B
  4. Quick Check:

    Return boolean from error handler [OK]
Quick Trick: Return true or false from error handler, not numbers [OK]
Common Mistakes:
  • Returning integers instead of booleans
  • Assuming four parameters are mandatory
  • Thinking echo is forbidden in handler

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes