Bird
Raised Fist0
PHPprogramming~20 mins

PHP error types and levels - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
PHP Error Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output of this PHP code with error reporting?
Consider the following PHP code snippet. What will be the output when run with error reporting set to E_ALL?
PHP
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

// Undefined variable usage
echo $undefinedVar;
?>
AWarning: Undefined variable: undefinedVar in /path/to/script.php on line 6
BFatal error: Undefined variable: undefinedVar in /path/to/script.php on line 6
CNotice: Undefined variable: undefinedVar in /path/to/script.php on line 6
DNo output, script runs silently
Attempts:
2 left
💡 Hint
Undefined variables trigger notices, not warnings or fatal errors.
❓ Predict Output
intermediate
2:00remaining
What error level is triggered by this PHP code?
What type of error does the following PHP code produce?
PHP
<?php
// Division by zero
$result = 10 / 0;
?>
AParse error: Division by zero
BWarning: Division by zero
CFatal error: Division by zero
DNotice: Division by zero
Attempts:
2 left
💡 Hint
Division by zero is a runtime warning, not a fatal error.
❓ Predict Output
advanced
2:00remaining
What error does this PHP code produce?
What error message will this PHP code output?
PHP
<?php
// Call to undefined function
undefinedFunction();
?>
AParse error: Call to undefined function undefinedFunction()
BWarning: Call to undefined function undefinedFunction()
CNotice: Call to undefined function undefinedFunction()
DFatal error: Uncaught Error: Call to undefined function undefinedFunction()
Attempts:
2 left
💡 Hint
Calling a function that does not exist causes a fatal error.
❓ Predict Output
advanced
2:00remaining
What error level is triggered by this PHP code?
What error level does this PHP code produce?
PHP
<?php
// Including a non-existent file
include('missingfile.php');
?>
AWarning: include(missingfile.php): failed to open stream
BFatal error: include(missingfile.php): failed to open stream
CNotice: include(missingfile.php): failed to open stream
DParse error: include(missingfile.php): failed to open stream
Attempts:
2 left
💡 Hint
include() triggers a warning if the file is missing, but script continues.
❓ Predict Output
expert
3:00remaining
What is the output of this PHP error handling code?
What will be the output of this PHP code snippet?
PHP
<?php
error_reporting(E_ERROR | E_PARSE);
ini_set('display_errors', 1);

// Trigger notice
echo $var;

// Trigger warning
include('nofile.php');

// Trigger fatal error
undefinedFunc();
?>
AFatal error: Uncaught Error: Call to undefined function undefinedFunc()
B
Notice: Undefined variable: var
Warning: include(nofile.php): failed to open stream
CNo output, all errors suppressed
D
Warning: include(nofile.php): failed to open stream
Fatal error: Uncaught Error: Call to undefined function undefinedFunc()
Attempts:
2 left
💡 Hint
Only E_ERROR and E_PARSE are reported; notices and warnings are ignored.

Practice

(1/5)
1. Which PHP error type indicates a problem that stops the script from running?
easy
A. Warning
B. Fatal error
C. Notice
D. Deprecated

Solution

  1. Step 1: Understand PHP error types

    Fatal errors are serious problems that stop the script immediately.
  2. Step 2: Compare with other error types

    Warnings and notices do not stop the script; deprecated warns about old code.
  3. Final Answer:

    Fatal error -> Option B
  4. Quick Check:

    Fatal error = stops script [OK]
Hint: Fatal errors stop scripts immediately, others do not [OK]
Common Mistakes:
  • Confusing warnings with fatal errors
  • Thinking notices stop script execution
  • Mixing deprecated warnings with fatal errors
2. Which of the following is the correct way to set PHP to report all errors except notices?
easy
A. error_reporting(E_ALL & ~E_NOTICE);
B. error_reporting(E_ALL | E_NOTICE);
C. error_reporting(E_ALL & E_NOTICE);
D. error_reporting(E_ALL ^ E_NOTICE);

Solution

  1. Step 1: Understand error_reporting flags

    E_ALL means all errors; ~E_NOTICE means exclude notices using bitwise NOT.
  2. Step 2: Analyze each option

    error_reporting(E_ALL & ~E_NOTICE); uses bitwise AND with NOT (~) to exclude notices correctly.
  3. Final Answer:

    error_reporting(E_ALL & ~E_NOTICE); -> Option A
  4. Quick Check:

    Exclude notices with & ~E_NOTICE [OK]
Hint: Use & ~E_NOTICE to exclude notices from all errors [OK]
Common Mistakes:
  • Using | instead of & ~ to exclude errors
  • Confusing ^ (XOR) with exclusion
  • Using & E_NOTICE which includes only notices
3. What will be the output of this PHP code?
<?php
error_reporting(E_ERROR | E_WARNING);
echo $undefined_variable;
include('missing_file.php');
?>
medium
A. Warning about missing file only
B. Fatal error about missing file
C. Notice about undefined variable and warning about missing file
D. No output, script runs silently

Solution

  1. Step 1: Check error_reporting level

    Only E_ERROR and E_WARNING are reported; notices are not shown.
  2. Step 2: Analyze code behavior

    Undefined variable triggers a notice (not shown). Missing file triggers a warning (shown).
  3. Final Answer:

    Warning about missing file only -> Option A
  4. Quick Check:

    E_WARNING shown, notices hidden [OK]
Hint: Only errors and warnings show; notices are hidden [OK]
Common Mistakes:
  • Expecting notice output when it's excluded
  • Confusing warning with fatal error
  • Thinking script stops on warning
4. Identify the error in this PHP code snippet:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 0);
echo $undefined_var;
?>
medium
A. Errors will be displayed despite display_errors set to 0
B. No errors will be reported because error_reporting is off
C. Syntax error due to missing semicolon
D. Errors are reported but not displayed due to display_errors=0

Solution

  1. Step 1: Understand error_reporting and display_errors

    error_reporting(E_ALL) enables all error reporting; display_errors=0 hides errors from output.
  2. Step 2: Analyze code behavior

    Errors are logged/reported internally but not shown on screen because display_errors is off.
  3. Final Answer:

    Errors are reported but not displayed due to display_errors=0 -> Option D
  4. Quick Check:

    display_errors=0 hides errors, reporting still active [OK]
Hint: display_errors=0 hides errors; error_reporting controls reporting [OK]
Common Mistakes:
  • Thinking errors won't be reported at all
  • Confusing display_errors with error_reporting
  • Assuming syntax error due to missing semicolon
5. You want to show all errors except deprecated warnings during development but hide all errors on the live site. Which code setup achieves this best?
hard
A. error_reporting(E_ALL); ini_set('display_errors', 1);
B. error_reporting(E_ALL & ~E_NOTICE); ini_set('display_errors', 0);
C. if (ENV == 'dev') { error_reporting(E_ALL & ~E_DEPRECATED); ini_set('display_errors', 1); } else { error_reporting(0); ini_set('display_errors', 0); }
D. if (ENV == 'prod') { error_reporting(E_ALL); ini_set('display_errors', 1); } else { error_reporting(0); ini_set('display_errors', 0); }

Solution

  1. Step 1: Understand environment-based error settings

    During development (dev), show all errors except deprecated; on live (prod), hide all errors.
  2. Step 2: Analyze each option

    if (ENV == 'dev') { error_reporting(E_ALL & ~E_DEPRECATED); ini_set('display_errors', 1); } else { error_reporting(0); ini_set('display_errors', 0); } correctly uses error_reporting with exclusion and display_errors on dev, off on live.
  3. Final Answer:

    if (ENV == 'dev') { error_reporting(E_ALL & ~E_DEPRECATED); ini_set('display_errors', 1); } else { error_reporting(0); ini_set('display_errors', 0); } -> Option C
  4. Quick Check:

    Dev shows errors except deprecated; live hides all [OK]
Hint: Use environment check to toggle error reporting and display [OK]
Common Mistakes:
  • Showing errors on live site
  • Not excluding deprecated warnings during dev
  • Confusing environment variable names
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard