SoFunction
Updated on 2025-03-02

Summary of the lowest level error types in PHP

Preface: A php error is a situation where the script runs abnormally.

There are many types of php errors, including warning, notice, deprecated, fetal error, etc. Among them, notice is not called notification, but an error at the notification level, and warning is not called warning, but an error at the warning level.

Errors are roughly divided into the following types

  • deprecated is the lowest level error, which means "not recommended, not recommended". For example, the regular matching function of the ereg series used in PHP5 will report such an error. This error is usually caused by the use of unrecommended, outdated functions or syntax. Although it does not affect the normal PHP process, it is generally recommended to correct it.
  • The second is notice. This kind of error is generally an inappropriate part of the grammar. This error will be reported if a variable is used but not defined. The most common thing is that when the array index is a character, there are no quotes. PHP treats it as a constant. First look up the constant table, and then it is considered a variable if it cannot be found. Although PHP is a scripting language and has poor syntax requirements, it is still recommended to initialize variables. This error does not affect the normal PHP process.
  • Warning is a relatively high-level error. This error will only be reported when there are very inappropriate situations in the syntax, such as mismatch in function parameters. This level of error will lead to failure to get the expected results and the code needs to be modified.
  • A higher level of error is fetal error. This is a fatal error, which directly causes the PHP process to terminate and the subsequent code will no longer be executed. This problem must be corrected
  • A high-level error is a syntax parsing error. The errors mentioned above all belong to the error during the PHP code running, while the syntax parsing error belongs to the syntax checking stage error, which will cause the PHP code to fail to pass the syntax checking.

Here are just a few of the most common ones, there are 16 levels of errors in the php manual.

$date = date('Y-m-d');;
if(ereg("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})",$date,$regs)){
echo $regs[1]."-".$regs[2]."-".$regs[3];
}else{
echo "No match";
}
//Deprecated (in php5 version), Fatal error (in php7 version)
if($i > 2020){
echo '$i is not initialized!!!',PHP_EOL;
}
//Notice

$arr = array('arr'=>1,2,3);
echo $arr[arr];
//Warning

$res = array_sum($arr,1);
//Warning

echo fun();
//Fatal error

echo "Highest level error';
//Parse error

The above code demonstrates several common error levels in PHP. If the output is not complete, you can check the configuration file to see if it is set as follows.

error_reporting=E_ALL | E_STRICT
display_errors=On

The error_reporting specifies the error level, so it goes without saying that display_errors.

This is the end of this article about the lowest-level error types in PHP. For more information about the lowest-level error types in PHP, please search for my previous articles or continue browsing the related articles below. I hope you will support me in the future!