Bird
0
0

Consider this code:

medium📝 Predict Output Q5 of 15
PHP - Error and Exception Handling
Consider this code:
function errorHandler($errno, $errstr) {
  echo "Error [$errno]: $errstr";
  return false;
}
set_error_handler('errorHandler');
trigger_error('Test error', E_USER_WARNING);

What will be the output?
AError [512]: Test error
BWarning: Test error
CError [512]: Test errorWarning: Test error
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Understand return false in custom error handler

    Returning false tells PHP to execute the default error handler after the custom one.
  2. Step 2: Analyze output from both handlers

    The custom handler prints "Error [512]: Test error" and then PHP prints the default warning message.
  3. Final Answer:

    Error [512]: Test errorWarning: Test error -> Option C
  4. Quick Check:

    Return false = custom + default error output [OK]
Quick Trick: Return false to run default error handler after custom [OK]
Common Mistakes:
  • Assuming only custom handler output appears
  • Expecting no output when returning false
  • Confusing error number with error type

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes