Complete the code to set a custom error handler function named 'myErrorHandler'.
<?php
set_error_handler([1]);
?>The set_error_handler function expects the name of the error handler function as a string. So, you pass it as "myErrorHandler".
Complete the code to define a custom error handler function that accepts the error number and error message.
<?php function myErrorHandler([1], $errstr) { echo "Error: $errstr"; } ?>
The first parameter of a custom error handler function is usually named $errno, which holds the error number.
Fix the error in the code to correctly set the custom error handler function.
<?php set_error_handler(myErrorHandler); ?>
The function name must be passed as a string with double quotes to set_error_handler. Without quotes, PHP treats it as a constant or function call, causing an error.
Fill both blanks to create a custom error handler that logs errors to a file named 'errors.log'.
<?php function myErrorHandler([1], $errstr) { error_log($errstr, [2], "errors.log"); } ?>
The first parameter is the error number $errno. The second argument to error_log is the message type; 3 means to append the error message to the specified file.
Fill all three blanks to set a custom error handler that ignores warnings (error level 2) and logs other errors to 'errors.log'.
<?php function myErrorHandler([1], $errstr) { if ([2] == 2) { return true; } error_log($errstr, [3], "errors.log"); } set_error_handler("myErrorHandler"); ?>
The error number parameter is $errno. To ignore warnings, check if $errno == 2. Use 3 as the message type in error_log to log errors to a file.