0
0
PHPprogramming~10 mins

Set_error_handler function in PHP - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set a custom error handler function named 'myErrorHandler'.

PHP
<?php
set_error_handler([1]);
?>
Drag options to blanks, or click blank then click option'
A"myErrorHandler"
BmyErrorHandler()
CerrorHandler
DhandleError
Attempts:
3 left
💡 Hint
Common Mistakes
Calling the function instead of passing its name.
Passing the function name without quotes.
2fill in blank
medium

Complete the code to define a custom error handler function that accepts the error number and error message.

PHP
<?php
function myErrorHandler([1], $errstr) {
    echo "Error: $errstr";
}
?>
Drag options to blanks, or click blank then click option'
A$errorNumber
B$errno
C$errnum
D$error
Attempts:
3 left
💡 Hint
Common Mistakes
Using a parameter name that is not descriptive or standard.
Missing the first parameter entirely.
3fill in blank
hard

Fix the error in the code to correctly set the custom error handler function.

PHP
<?php
set_error_handler(myErrorHandler);
?>
Drag options to blanks, or click blank then click option'
A'myErrorHandler'
BmyErrorHandler()
C"myErrorHandler"
DmyErrorHandler
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the function name without quotes.
Calling the function instead of passing its name.
4fill in blank
hard

Fill both blanks to create a custom error handler that logs errors to a file named 'errors.log'.

PHP
<?php
function myErrorHandler([1], $errstr) {
    error_log($errstr, [2], "errors.log");
}
?>
Drag options to blanks, or click blank then click option'
A$errno
B3
C0
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong parameter names.
Using incorrect message type for error_log.
5fill in blank
hard

Fill all three blanks to set a custom error handler that ignores warnings (error level 2) and logs other errors to 'errors.log'.

PHP
<?php
function myErrorHandler([1], $errstr) {
    if ([2] == 2) {
        return true;
    }
    error_log($errstr, [3], "errors.log");
}
set_error_handler("myErrorHandler");
?>
Drag options to blanks, or click blank then click option'
A$errno
B$errnum
C3
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names for error number.
Checking wrong error level.
Using wrong message type in error_log.