0
0
PHPprogramming~10 mins

PHP error types and levels - Interactive Code Practice

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

Complete the code to display all errors except notices.

PHP
<?php
error_reporting([1]);
?>
Drag options to blanks, or click blank then click option'
AE_WARNING
BE_ERROR
CE_NOTICE
DE_ALL & ~E_NOTICE
Attempts:
3 left
💡 Hint
Common Mistakes
Using only E_ALL reports notices too.
Using E_NOTICE alone reports only notices.
2fill in blank
medium

Complete the code to trigger a user error with a custom message.

PHP
<?php
trigger_error([1], E_USER_ERROR);
?>
Drag options to blanks, or click blank then click option'
A"Warning: Something went wrong"
B"Custom error occurred"
CE_USER_WARNING
DE_ERROR
Attempts:
3 left
💡 Hint
Common Mistakes
Passing error level constants instead of a message string.
Omitting quotes around the message.
3fill in blank
hard

Fix the error in the code to set error reporting to show only warnings.

PHP
<?php
error_reporting([1]);
?>
Drag options to blanks, or click blank then click option'
AE_WARNING
BE_NOTICE
CE_ALL
DE_ERROR
Attempts:
3 left
💡 Hint
Common Mistakes
Using E_ALL reports all errors, not just warnings.
Using E_NOTICE reports notices, not warnings.
4fill in blank
hard

Fill both blanks to set error reporting to show all errors except deprecated and strict notices.

PHP
<?php
error_reporting(E_ALL & ~[1] & ~[2]);
?>
Drag options to blanks, or click blank then click option'
AE_DEPRECATED
BE_STRICT
CE_NOTICE
DE_WARNING
Attempts:
3 left
💡 Hint
Common Mistakes
Excluding E_NOTICE instead of E_DEPRECATED or E_STRICT.
Using bitwise OR instead of AND.
5fill in blank
hard

Fill all three blanks to create a custom error handler function that handles warnings and notices.

PHP
<?php
function customErrorHandler([1], $errstr, $errfile, $errline) {
    if ($errNo & ([2] | [3])) {
        echo "Custom error: $errstr in $errfile on line $errline";
    }
}
set_error_handler('customErrorHandler');
?>
Drag options to blanks, or click blank then click option'
A$errNo
BE_WARNING
CE_NOTICE
D$errNo &
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect variable names for the error number.
Using bitwise AND incorrectly in the condition.