Bird
0
0

How do you correctly assign a custom error handler function named handleError using set_error_handler in PHP?

easy📝 Syntax Q3 of 15
PHP - Error and Exception Handling
How do you correctly assign a custom error handler function named handleError using set_error_handler in PHP?
Aset_error_handler('handleError');
Bset_error_handler(handleError);
Cset_error_handler(&handleError);
Dset_error_handler(handleError());
Step-by-Step Solution
Solution:
  1. Step 1: Understand function parameter

    The set_error_handler function expects the name of the handler as a string.
  2. Step 2: Analyze options

    set_error_handler('handleError'); passes the function name as a string, which is correct. set_error_handler(handleError); passes it as a bareword (undefined constant), C uses an invalid reference, and D calls the function immediately, which is incorrect.
  3. Final Answer:

    set_error_handler('handleError'); -> Option A
  4. Quick Check:

    Function name must be a string [OK]
Quick Trick: Function name must be a string [OK]
Common Mistakes:
  • Passing function name without quotes
  • Using function call instead of name
  • Using invalid references or variables

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes