Bird
0
0

What will be the output of this PHP code?

medium📝 Predict Output Q4 of 15
PHP - Error and Exception Handling
What will be the output of this PHP code?
function myErrorHandler($errno, $errstr) {
  echo "Error: $errstr";
  return true;
}
set_error_handler('myErrorHandler');
echo 10 / 0;
AWarning: Division by zero
BError: Division by zero
CFatal error: Division by zero
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Understand error handling with set_error_handler

    The custom handler replaces PHP's default error message and outputs the error string.
  2. Step 2: Analyze the division by zero error

    Division by zero triggers a warning, caught by the handler which echoes "Error: Division by zero".
  3. Final Answer:

    Error: Division by zero -> Option B
  4. Quick Check:

    Custom handler output = error message printed [OK]
Quick Trick: Custom handler outputs error message instead of default warning [OK]
Common Mistakes:
  • Expecting default PHP warning output
  • Thinking division by zero causes fatal error
  • Assuming no output is shown

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes