0
0
PHPprogramming~10 mins

PHP error types and levels - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - PHP error types and levels
Start PHP script
Code runs
Error occurs?
NoScript continues
Yes
Identify error type
Match error level
Handle error (display/log/ignore)
Script ends or continues
PHP runs code and checks if an error happens. If yes, it finds the error type and level, then handles it accordingly.
Execution Sample
PHP
<?php
// Trigger different error levels
trigger_error("Notice example", E_USER_NOTICE);
trigger_error("Warning example", E_USER_WARNING);
trigger_error("Error example", E_USER_ERROR);
?>
This code triggers three different PHP error levels: notice, warning, and fatal error.
Execution Table
StepActionError Triggered?Error TypeError LevelEffect
1Run trigger_error with E_USER_NOTICEYesUser NoticeE_USER_NOTICENotice message shown, script continues
2Run trigger_error with E_USER_WARNINGYesUser WarningE_USER_WARNINGWarning message shown, script continues
3Run trigger_error with E_USER_ERRORYesUser ErrorE_USER_ERRORFatal error message shown, script stops
4Script tries to continue after fatal errorNo--Script stops, no further execution
💡 Script stops after fatal error (E_USER_ERROR) because it is a critical error level.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
error_triggeredfalsetrue (notice)true (warning)true (fatal error)script stopped
script_statusrunningrunningrunningstoppedstopped
Key Moments - 3 Insights
Why does the script stop after the third error but not after the first two?
Because E_USER_ERROR is a fatal error level that stops script execution, unlike E_USER_NOTICE and E_USER_WARNING which only show messages but allow the script to continue (see execution_table rows 1-3).
Are notices and warnings errors that break the program?
No, notices and warnings inform about issues but do not stop the program. Only fatal errors stop execution (see execution_table rows 1 and 2).
What happens if an error level is not handled?
PHP uses default behavior: notices and warnings show messages, fatal errors stop the script. Custom handlers can change this (not shown here).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what error level causes the script to stop?
AE_USER_NOTICE
BE_USER_ERROR
CE_USER_WARNING
DNo error stops the script
💡 Hint
Check the Effect column in execution_table row 3 where the script stops.
At which step does the script still continue running after an error?
ASteps 1 and 2
BStep 1 only
CStep 3 only
DNo steps, script stops immediately
💡 Hint
Look at script_status in variable_tracker after Step 1 and Step 2.
If the third trigger_error used E_USER_WARNING instead of E_USER_ERROR, what would happen?
AScript would stop immediately at step 1
BScript would stop at step 3
CScript would continue after step 3
DNo error messages would show
💡 Hint
Refer to the Effect column for E_USER_WARNING in execution_table rows 2 and 3.
Concept Snapshot
PHP errors have types and levels:
- Notice (E_USER_NOTICE): minor, script continues
- Warning (E_USER_WARNING): important, script continues
- Fatal Error (E_USER_ERROR): critical, script stops
Use trigger_error() to create errors.
Script stops only on fatal errors.
Full Transcript
PHP runs code and checks for errors. Errors have types like Notice, Warning, and Fatal Error. Notices and Warnings show messages but let the script keep running. Fatal Errors stop the script immediately. The example code triggers one of each error type. The execution table shows the script continues after Notice and Warning but stops after Fatal Error. Variables track if an error happened and if the script is running. Beginners often wonder why some errors stop the script and others don't. The key is the error level. This helps understand how PHP handles problems during execution.