0
0
PHPprogramming~20 mins

PHP error types and levels - Mini Project: Build & Apply

Choose your learning style9 modes available
Understanding PHP Error Types and Levels
📖 Scenario: You are building a simple PHP script to learn about different types of errors and how PHP reports them. This will help you understand how to spot and fix problems in your PHP code.
🎯 Goal: Create a PHP script that defines error reporting levels, triggers different types of errors, and displays the error messages.
📋 What You'll Learn
Create variables and settings to control error reporting
Trigger different PHP error types: notice, warning, and fatal error
Display error messages according to the error reporting level
💡 Why This Matters
🌍 Real World
Understanding PHP error types helps you debug your web applications and fix problems quickly.
💼 Career
PHP developers must know how to handle errors to write reliable and maintainable code.
Progress0 / 4 steps
1
Set up error reporting levels
Write PHP code to set the error reporting level to show all errors using error_reporting(E_ALL); and enable displaying errors with ini_set('display_errors', '1');.
PHP
Need a hint?

Use error_reporting(E_ALL); to report all errors and ini_set('display_errors', '1'); to show them on the screen.

2
Trigger a notice error
Add PHP code that tries to use an undefined variable called $undefinedVar to trigger a notice error.
PHP
Need a hint?

Simply try to print $undefinedVar without defining it first.

3
Trigger a warning error
Add PHP code to include a file named missingfile.php using include to trigger a warning error.
PHP
Need a hint?

Use include 'missingfile.php'; to cause a warning because the file does not exist.

4
Trigger a fatal error
Add PHP code to call a function named undefinedFunction() that does not exist to trigger a fatal error. Then print "End of script" using echo.
PHP
Need a hint?

Call undefinedFunction(); to cause a fatal error. The last echo will not run because of the fatal error.